0

I am using a python script which runs OBJDUMP to extract dwarf information from an elf file, this is part of the code:

    # Run objdump to extract DWARF information from the ELF file
    ps = subprocess.Popen(path + "\\objdump --dwarf=info " + elf_file_name, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    dwarf = ps.communicate()[0]

    # Iterate through each line of the decoded DWARF output
    for line in dwarf.decode("ascii").split('\n'):
        if line.strip().startswith("<"):
            .....
            .....

the problem is when i iterate through each line of the decoded DWARF output, it will have different ways of extracting variable information, for instance if i have 3 letters variables it will get only the name of the variable but if i have more than 3 letters it will get more information, you can see the photos below, does anyone have any idea why i get this.

enter image description here

enter image description here

Thank you.

4
  • 1
    Why is this a problem? Commented Apr 26, 2024 at 11:39
  • 1
    For me it is because i have a script which retrieve information for each variable, so when i used 3 letter variable it didn't work, then when i debugged it i found out this, so i added a new handling, and i was wondering is this the only case in which it will not work or there are other cases which i don't know about Commented Apr 29, 2024 at 9:25
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Apr 29, 2024 at 16:30
  • Why parse objdump output? There are perfectly capable Python native DWARF parsing libraries. pyelftools is popular, for example. It resolves strp out of the box. Commented Nov 25, 2024 at 20:22

1 Answer 1

0

if i have 3 letters variables it will get only the name of the variable but if i have more than 3 letters it will get more information, …, does anyone have any idea why i get this.

The OSDev Wiki says:

If most attributes have a fixed size, a few attributes need to have some special handling:

  • DW_FORM_string attributes are a small zero-terminated string (so of variable length)
  • DW_FORM_strp attributes represent the offset inside the .debug_str section of the desired string

Of course you can only get more information (the offset into the .debug_str section) if it is there.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response. Okey so the only thing i need to do is have some kind of handling for when i have extra information and when i don't have extra info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.