Is there any simple and clear way to implement this?
No.
To implement this, you would need to have a detailed understanding of how the debug info is encoded, and how to interpret it.
I assume I need a parser of dwarf format, find
AT_DW_location
of arguments in.debug_info
, maybe then refer to.debug_loc
for location list ...
Yes, and more. You could compile your example program, and then study the output from readelf -wi a.out
.
Look for DW_TAG_subprogram
, followed by DW_TAG_formal_parameter
s. Each parameter will have DW_AT_type
and DW_AT_location
, which will tell you the type and location of the parameter.
I don't know if this is a feasible
It's feasible, but by the time you are done you will have implemented 30-50% of a real debugger. At which point a reasonable question is: why not use a real debugger which exists already?