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

How to use this tool to retrieve global variables #385

Open
Plyees opened this issue Nov 26, 2021 · 6 comments
Open

How to use this tool to retrieve global variables #385

Plyees opened this issue Nov 26, 2021 · 6 comments

Comments

@Plyees
Copy link

Plyees commented Nov 26, 2021

I am looking to retrieve all global variables from debuginfo that is generated for C application under Ubuntu. Could anyone please kindly give me a hint?

@sevaa
Copy link
Contributor

sevaa commented Nov 26, 2021

Use https://github.com/eliben/pyelftools/blob/master/examples/dwarf_die_tree.py as the starting point. The example scrolls through all CUs and DIEs in the file; you'd have to write a condition that would identify a variable (start with die.tag = "DW_TAG_variable", but that's probably not sufficient), then dump whatever variable properties you are interested in.

Variables inside functions are not globals. I don't know if function scoped static variables qualify for your case.

@Plyees
Copy link
Author

Plyees commented Nov 26, 2021

Thank you for your hint. I have tried to explore into DIE to assemble variables, but blocked by some variables with a mix of structure and array involving multiple recursion.

@Plyees
Copy link
Author

Plyees commented Nov 26, 2021

function scoped variables are not my interest. My debuginfo seems containing only global variables defined outside the functions

@sevaa
Copy link
Contributor

sevaa commented Nov 26, 2021

I take it, you are interested in datatypes, too.

In general, spelling out the datatype of a C++ variable from DWARF data is a very tricky task. Between classes, templates, namespaces, typedefs, const-ness, and function pointers (where you have to spell out the type of each argument), it's a major pain. I have a semi-working piece of Python code that sort of spells the datatype for the subset of DWARF that is relevant to me, but it's a work in progress and it isn't public.

@sevaa
Copy link
Contributor

sevaa commented Sep 22, 2023

Update: a version of that logic found its way into pyelftools proper. See describe_cpp_datatype in elftools/dwarf/datatype_cpp.

It was tested on the small corpus of binaries that we have. Needless say, not nearly exhaustive. Also, it stops on typedefs (in line with what llvm-dwarfdump does) rather than parsing down to the basic types.

@sevaa
Copy link
Contributor

sevaa commented Apr 12, 2024

@Plyees is still an issue?

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

2 participants