Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
sources.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 #
3 # File: GdbUtils/python/sources.py
4 # Created: A while ago, sss
5 # Purpose: Try to automatically set source file paths for an ATLAS build.
6 #
7 
8 import os
9 import gdb
10 
11 # Set source path for ROOT.
12 # rootsys = os.environ.get ('ROOTSYS')
13 # if rootsys:
14 # rootsys = os.path.dirname (rootsys)
15 # rootsys = os.path.dirname (rootsys)
16 # rootsys = os.path.join (rootsys, 'src', 'root')
17 # if os.path.exists (rootsys):
18 # gdb.execute ("dir %s" % rootsys)
19 
20 
21 # Hacks to set other source paths properly.
22 
23 # def _handle_atlas_buildarea (fname):
24 # # Work around realpath bug in py 2.3.
25 # if os.path.islink(fname):
26 # fname = os.path.join (os.path.dirname (fname),
27 # os.readlink (fname))
28 # fname = os.path.realpath (fname)
29 # if os.path.exists (fname):
30 # fname = os.path.dirname (fname)
31 # pkgdir = os.path.dirname (fname)
32 # pkg = os.path.basename (pkgdir)
33 # gdb.execute ("dir %s" % os.path.join (pkgdir, 'src'))
34 # gdb.execute ("dir %s" % os.path.join (pkgdir, pkg))
35 # return
36 
37 # _lcg_done = ['ROOT'] # root's handled separately.
38 # def _handle_lcgarea (fname):
39 # fname = os.path.realpath (fname)
40 # if os.path.exists (fname):
41 # fname = os.path.dirname (fname) # .../lib
42 # fname = os.path.dirname (fname) # .../arch
43 # fname = os.path.dirname (fname) # .../PRODUCT_VERSION
44 
45 # product = os.path.dirname (fname) # .../PRODUCT
46 # product = os.path.basename (fname) # PRODUCT
47 # if product in _lcg_done: return
48 # srcdir = os.path.join (fname, 'src')
49 # if not os.path.exists (srcdir): return
50 # paths = os.listdir (srcdir)
51 # for p in paths:
52 # dir = os.path.join (srcdir, p, 'src')
53 # if os.path.exists (dir):
54 # gdb.execute ("dir %s" % dir)
55 # dir = os.path.join (srcdir, p, p)
56 # if os.path.exists (dir):
57 # gdb.execute ("dir %s" % dir)
58 # return
59 
60 
61 _handled_dirs=set()
62 def handle_comp_dir (fname, dirname):
63  if dirname in _handled_dirs:
64  return
65  _handled_dirs.add (dirname)
66  if not dirname.startswith ('/build'): return
67 
68  pos = dirname.rfind ('/build/')
69  if pos < 0: return
70  pos += 7
71  pos = dirname.find ('/', pos)
72  if pos < 0: return
73  pack = dirname[pos+1:]
74 
75  pos = fname.find ('/InstallArea/')
76  if pos < 0: return
77  pos += 13
78  pos = fname.find ('/', pos)
79  if pos < 0: return
80  srcroot = fname[:pos] + '/src'
81  pdir = srcroot + '/' + pack
82  for (dirpath, dirnames, filenames) in os.walk (pdir):
83  print ('dir ' + dirpath)
84  gdb.execute ('dir ' + dirpath)
85  return
86 
87 _handled=set()
89  if fname in _handled:
90  return
91  import subprocess
92  files = set()
93  out = subprocess.getoutput ('objdump --dwarf=info %s | grep DW_AT_comp_dir' % fname)
94  for l in out.split('\n'):
95  pos = l.find('/')
96  if pos >= 0:
97  files.add (l[pos:].strip())
98  for f in files:
99  handle_comp_dir (fname, f)
100  _handled.add(fname)
101  return
102 
103 
104 def _objfile_hook (ev):
105  o = ev.new_objfile
106  if o.filename.startswith ('/cvmfs'):
107  handle_atlas_buildarea (o.filename)
108  return
109 
110 gdb.events.new_objfile.connect (_objfile_hook)
python.sources._objfile_hook
def _objfile_hook(ev)
Definition: sources.py:104
python.sources.handle_comp_dir
def handle_comp_dir(fname, dirname)
Definition: sources.py:62
python.sources.handle_atlas_buildarea
def handle_atlas_buildarea(fname)
Definition: sources.py:88
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232