pyelftools icon indicating copy to clipboard operation
pyelftools copied to clipboard

readelf.py --debug-dump=decodedline fails

Open smani opened this issue 11 years ago • 4 comments

Running python scripts/readelf.py --debug-dump=decodedline test/testfiles_for_unittests/arm_with_form_indirect.elf fails with the following error:

Traceback (most recent call last):
  File "scripts/readelf.py", line 1136, in <module>
    main()
  File "scripts/readelf.py", line 1115, in main
    readelf.display_debug_dump(options.debug_dump_what)
  File "scripts/readelf.py", line 635, in display_debug_dump
    self._dump_debug_line_programs()
  File "scripts/readelf.py", line 872, in _dump_debug_line_programs
    cu_filename = bytes2str(lineprogram['file_entry'][0].name)
TypeError: 'NoneType' object is not subscriptable

smani avatar Jan 19 '14 07:01 smani

I get the same error with the file I sent you in issue #22, but I thought it had something to do with the way the file is formatted. After reading the file using normal readelf, Using:

$ readelf --debug-dump=decodedline uvision/O0/obj/UserManualExample.axf

I get:

Decoded dump of debug contents of section .debug_line:

CU: ..\..\..\..\..\..\src\asm\/startup_SLE97.s:
File name                            Line number    Starting address
startup_SLE97.s                              117          0x100061dc

startup_SLE97.s                              118          0x100061e0
startup_SLE97.s                              119          0x100061e2
startup_SLE97.s                              121          0x100061e4
startup_SLE97.s                              122          0x100061e6
startup_SLE97.s                              123          0x100061e8
startup_SLE97.s                              124          0x100061ea
startup_SLE97.s                              132          0x100061ec
startup_SLE97.s                              133          0x100061ee
startup_SLE97.s                              138          0x100061f0
startup_SLE97.s                              139          0x100061f2
startup_SLE97.s                              144          0x100061f4
startup_SLE97.s                              145          0x100061f6
startup_SLE97.s                              150          0x100061f8
startup_SLE97.s                              151          0x100061fa
startup_SLE97.s                              156          0x100061fc
startup_SLE97.s                              157          0x100061fe
startup_SLE97.s                              162          0x10006200
startup_SLE97.s                              163          0x10006202
startup_SLE97.s                              168          0x10006204
startup_SLE97.s                              169          0x10006206
startup_SLE97.s                              173          0x10006208
startup_SLE97.s                              174          0x1000620a
startup_SLE97.s                              178          0x1000620c
startup_SLE97.s                              179          0x1000620e
startup_SLE97.s                              216          0x10006210
startup_SLE97.s                              217          0x10006212
startup_SLE97.s                              228          0x10006214
startup_SLE97.s                              249          0x10006218

startup_SLE97.s                              250          0x1000621a
startup_SLE97.s                              251          0x1000621c
startup_SLE97.s                              252          0x1000621e
startup_SLE97.s                              253          0x10006220

CU: ..\..\..\..\..\..\src\c\/system_m9900_usermailbox.h:
File name                            Line number    Starting address

CU: C:\keil\ARM\Inc\Infineon\SLE90\/FW_M9900_A22.h:
File name                            Line number    Starting address

CU: ..\..\..\..\..\..\src\c\/system_SLE90.c:
File name                            Line number    Starting address
system_SLE90.c                                80          0x100060f0

system_SLE90.c                               358          0x100060f2
system_SLE90.c                               358          0x100060f4
system_SLE90.c                               353          0x100060f6
system_SLE90.c                               353          0x100060f8
system_SLE90.c                               322          0x100060fa
system_SLE90.c                               327          0x100060fc
system_SLE90.c                               327          0x100060fe
system_SLE90.c                               328          0x10006102
system_SLE90.c                               328          0x10006104
system_SLE90.c                               333          0x10006108
system_SLE90.c                               338          0x1000610a
system_SLE90.c                               338          0x1000610c
system_SLE90.c                               346          0x10006110
system_SLE90.c                               346          0x10006112
system_SLE90.c                                92          0x10006114
system_SLE90.c                                95          0x10006116
system_SLE90.c                                99          0x10006118
system_SLE90.c                                99          0x1000611a
system_SLE90.c                               117          0x1000611c
system_SLE90.c                               117          0x1000611e
system_SLE90.c                               118          0x1000612a
system_SLE90.c                               118          0x1000612c
system_SLE90.c                               121          0x10006138
system_SLE90.c                               121          0x1000613a
system_SLE90.c                               122          0x10006140
system_SLE90.c                               122          0x10006142
system_SLE90.c                               125          0x10006146
system_SLE90.c                               125          0x10006148
system_SLE90.c                               127          0x1000614a
system_SLE90.c                               127          0x1000614c
system_SLE90.c                               128          0x10006152
system_SLE90.c                               128          0x10006154
system_SLE90.c                               130          0x1000615a
system_SLE90.c                               130          0x1000615c
system_SLE90.c                               132          0x10006164
system_SLE90.c                               132          0x10006166
system_SLE90.c                               136          0x1000616e
system_SLE90.c                               136          0x10006170
system_SLE90.c                               138          0x10006176
system_SLE90.c                               138          0x10006178
system_SLE90.c                               139          0x10006188
system_SLE90.c                               139          0x1000618a
system_SLE90.c                               142          0x10006190
system_SLE90.c                               142          0x10006192
system_SLE90.c                               144          0x10006196
system_SLE90.c                               144          0x10006198
system_SLE90.c                               146          0x1000619c
system_SLE90.c                               146          0x1000619e
system_SLE90.c                               241          0x100061a4
system_SLE90.c                               291          0x100061a6
system_SLE90.c                               291          0x100061a8
system_SLE90.c                               295          0x100061aa
system_SLE90.c                               296          0x100061ac
system_SLE90.c                               296          0x100061ae

CU: ./..\src\main.c:
File name                            Line number    Starting address

CU: C:\keil\ARM\ARMCC\bin\..\include\/stdint.h:
File name                            Line number    Starting address

CU: ..\src\main.c:
File name                            Line number    Starting address
..\src\main.c                                 41          0x100062ac

..\src\main.c                                 42          0x100062ae
..\src\main.c                                 44          0x100062b0
..\src\main.c                                 42          0x100062b2
..\src\main.c                                 42          0x100062b4
..\src\main.c                                 47          0x100062ba
..\src\main.c                                 51          0x100062bc
..\src\main.c                                 51          0x100062be
..\src\main.c                                 53          0x100062c6
..\src\main.c                                 53          0x100062c8
..\src\main.c                                 55          0x100062e4
..\src\main.c                                 55          0x100062e6

I am pretty sure the error comes from having two different CUs which are both from main.c. Do you think this is it? This is the standard output for armcc, so not sure what can be done from the compiling/elf side. Please let me know your thoughts. Roberto

crobertob avatar Jan 21 '14 14:01 crobertob

By the way. using the readelf.py script I get the following:

...
system_SLE90.c                               291          0x100061a8
system_SLE90.c                               295          0x100061aa
system_SLE90.c                               296          0x100061ac
system_SLE90.c                               296          0x100061ae

Traceback (most recent call last):
  File "readelf.py", line 1136, in <module>
    main()
  File "readelf.py", line 1115, in main
    readelf.display_debug_dump(options.debug_dump_what)
  File "readelf.py", line 635, in display_debug_dump
    self._dump_debug_line_programs()
  File "readelf.py", line 872, in _dump_debug_line_programs
    cu_filename = bytes2str(lineprogram['file_entry'][0].name)
TypeError: 'NoneType' object has no attribute '__getitem__'

crobertob avatar Jan 21 '14 14:01 crobertob

I managed to fix the code by checking that dwarfinfo.line_program_for_CU actually returns something:

lineprog = dwarfinfo.line_program_for_CU(CU)
     if lineprog != None:
          do stuff with get_entries

I guess this could be added to the examples (decode_address) and the readelf.py script. Cheers!

crobertob avatar Jan 21 '14 16:01 crobertob

Feel free to send a pull request with the fix

eliben avatar Jan 22 '14 00:01 eliben