Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

# Copyright (C) 2017 Free Software Foundation, Inc. 

 

# This program is free software; you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation; either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with GCC; see the file COPYING3. If not see 

# <http://www.gnu.org/licenses/>. 

 

# Helpers to parse and check DWARF in object files. 

# 

# The purpose of these is to make it easy to write "smart" tests on DWARF 

# information: pattern matching on DIEs and their attributes, check links 

# between DIEs, etc. Doing these checks using abstract representations of DIEs 

# is far easier than scanning the generated assembly! 

 

import os 

import sys 

 

import dwarfutils.objdump 

import testutils 

 

 

# Fetch the DWARF parsing function that correspond to the DWARF dump tool to 

# use. 

DWARF_DUMP_TOOL_KIND = os.environ['DWARF_DUMP_TOOL_KIND'] 

DWARF_DUMP_TOOL = os.environ['DWARF_DUMP_TOOL'] 

 

dwarf_parsers = { 

'objdump': dwarfutils.objdump.parse_dwarf, 

} 

try: 

dwarf_parser = dwarf_parsers[DWARF_DUMP_TOOL_KIND] 

except KeyError: # no-coverage 

raise RuntimeError('Unhandled DWARF dump tool: {}'.format( 

DWARF_DUMP_TOOL_KIND 

)) 

 

 

def parse_dwarf(object_file=None, single_cu=True): # no-coverage 

""" 

Fetch and decode DWARF compilation units in `object_file`. 

 

If `single_cu` is true, make sure there is exactly one compilation unit and 

return it. Otherwise, return compilation units as a list. 

 

:param str|None object_file: Name of the object file to process. If left to 

None, `sys.argv[1]` is used instead. 

 

:rtype: dwarfutils.data.CompilationUnit 

|list[dwarfutils.data.CompilationUnit] 

""" 

script_args = testutils.parse_args() 

result = dwarf_parser(script_args.object_file) 

 

if single_cu: 

if not result: 

return None 

if len(result) > 1: 

raise ValueError('Multiple compilation units found') 

return result[0] 

else: 

return result