Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying to obtain dwarf info: 'structs' is not defined #22

Closed
crobertob opened this issue Jan 15, 2014 · 8 comments
Closed

Error trying to obtain dwarf info: 'structs' is not defined #22

crobertob opened this issue Jan 15, 2014 · 8 comments

Comments

@crobertob
Copy link

Hello,
I'm trying to run the example examine_dwarf_info in an ELF file from Microvision but I receive the following error, could you please tell me if I'm doing something wrong or if there is a way to fix it? The example runs properly with the elf file provided as example. I'm using Python 2.7.3. Thank you.

Processing file: uvision/O0/obj/UserManualExample.axf
  Found a compile unit at offset 0, length 15044
Traceback (most recent call last):
  File "examine_dwarf_info.py", line 50, in <module>
    process_file(filename)
  File "examine_dwarf_info.py", line 42, in process_file
    top_DIE = CU.get_top_DIE()
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/compileunit.py", line 76, in get_top_DIE
    return self._get_DIE(0)
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/compileunit.py", line 95, in _get_DIE
    self._parse_DIEs()
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/compileunit.py", line 119, in _parse_DIEs
    offset=die_offset)
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/die.py", line 90, in __init__
    self._parse_DIE()
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/die.py", line 185, in _parse_DIE
    value = self._translate_attr_value(form, raw_value)
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/die.py", line 207, in _translate_attr_value
    structs.Dwarf_dw_form[form], self.stream)
NameError: global name 'structs' is not defined
@smani
Copy link
Contributor

smani commented Jan 15, 2014

This problem also happens with the ELF files generated by armcc/armlink tools. In _translate_attr_value, the local "structs" variable isn't initialized. I introduced "structs = self.cu.structs" and it didn't help either.

@eliben
Copy link
Owner

eliben commented Jan 15, 2014

Thanks for spotting and reporting the error. I've pushed a fix that should help, but you could you please (both @crobertob and @smani) post the smallest input files you ran into this problem with? This way I can add them to the tests. I don't appear to have any files that trigger the DW_FORM_indirect path now.

@crobertob
Copy link
Author

Thank you very much, you can find the input file here:
https://www.dropbox.com/s/hqghlq53h9imvzp/UserManualExample.axf

I will try out the fix now. Have a nice day!

@crobertob
Copy link
Author

After trying it out, I get a new error:

Processing file: O0/obj/UserManualExample.axf
  Found a compile unit at offset 0, length 15044
Traceback (most recent call last):
  File "examine_dwarf_info.py", line 50, in <module>
    process_file(filename)
  File "examine_dwarf_info.py", line 42, in process_file
    top_DIE = CU.get_top_DIE()
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/compileunit.py", line 76                                                                                                                                                 , in get_top_DIE
    return self._get_DIE(0)
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/compileunit.py", line 95                                                                                                                                                 , in _get_DIE
    self._parse_DIEs()
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/compileunit.py", line 11                                                                                                                                                 9, in _parse_DIEs
    offset=die_offset)
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/die.py", line 90, in __i                                                                                                                                                 nit__
    self._parse_DIE()
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/die.py", line 185, in _p                                                                                                                                                 arse_DIE
    value = self._translate_attr_value(form, raw_value)
  File "/usr/lib/python2.7/site-packages/elftools/dwarf/die.py", line 207, in _t                                                                                                                                                 ranslate_attr_value
    self.cu.structs.Dwarf_dw_form[form], self.stream)
KeyError: 17

Not sure what is the problem now.

@smani
Copy link
Contributor

smani commented Jan 15, 2014

Don't have a personal license to generate the ELF image from armcc/armlink. Sorry I couldn't provide a image. I can confirm that I also see the behavior like @crobertob.

@eliben
Copy link
Owner

eliben commented Jan 18, 2014

Thanks for the reproducing file. I think I got the problem fixed in trunk. Let me know how it works for you.

@eliben eliben closed this as completed Jan 18, 2014
@smani
Copy link
Contributor

smani commented Jan 19, 2014

Thanks for the fix. It works for me.

@crobertob
Copy link
Author

Thank you very much for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants