Reads the file tu.o and gets the binding (global or local) for each function :param tu: name of the translation unit (e.g. for main.c, this would be 'main') :param call_graph: a object used to store information about each function, results go here
(tu, call_graph)
| 49 | |
| 50 | |
| 51 | def read_obj(tu, call_graph): |
| 52 | """ |
| 53 | Reads the file tu.o and gets the binding (global or local) for each function |
| 54 | :param tu: name of the translation unit (e.g. for main.c, this would be 'main') |
| 55 | :param call_graph: a object used to store information about each function, results go here |
| 56 | """ |
| 57 | symbols = read_symbols(tu[0:tu.rindex(".")] + obj_ext) |
| 58 | |
| 59 | for s in symbols: |
| 60 | |
| 61 | if s.type == 'FUNC': |
| 62 | if s.binding == 'GLOBAL': |
| 63 | # Check for multiple declarations |
| 64 | if s.name in call_graph['globals'] or s.name in call_graph['locals']: |
| 65 | raise Exception('Multiple declarations of {}'.format(s.name)) |
| 66 | call_graph['globals'][s.name] = {'tu': tu, 'name': s.name, 'binding': s.binding} |
| 67 | elif s.binding == 'LOCAL': |
| 68 | # Check for multiple declarations |
| 69 | if s.name in call_graph['locals'] and tu in call_graph['locals'][s.name]: |
| 70 | raise Exception('Multiple declarations of {}'.format(s.name)) |
| 71 | |
| 72 | if s.name not in call_graph['locals']: |
| 73 | call_graph['locals'][s.name] = {} |
| 74 | |
| 75 | call_graph['locals'][s.name][tu] = {'tu': tu, 'name': s.name, 'binding': s.binding} |
| 76 | elif s.binding == 'WEAK': |
| 77 | if s.name in call_graph['weak']: |
| 78 | raise Exception('Multiple declarations of {}'.format(s.name)) |
| 79 | call_graph['weak'][s.name] = {'tu': tu, 'name': s.name, 'binding': s.binding} |
| 80 | else: |
| 81 | raise Exception('Error Unknown Binding "{}" for symbol: {}'.format(s.binding, s.name)) |
| 82 | |
| 83 | |
| 84 | def find_fxn(tu, fxn, call_graph): |