[SOLVED] Extract dwarf information debug a section
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to extract debug information but I have some problems.
For example, I have a executable a.out...
Quote:
nm -f sysv a.out | grep ".global_var" >vars.txt
With this command I extract all my variables. All of them are in .global_var section, and it give me follow information:
Quote:
CAN_station_n |08073258| D | OBJECT|00000001| |.global_var
CONTROLend |080732a7| D | OBJECT|00000001| |.global_var
CONTROLinit |080732a8| D | OBJECT|00000001| |.global_var
FORCEempty_changed |080732a5| D | OBJECT|00000001| |.global_var
FORCEmax_bar |08073283| D | OBJECT|00000007| |.global_var
FORCEmax_changed |080732a6| D | OBJECT|00000001| |.global_var
Well, I have only address of my vars, but I would like to know type var or struct of the variables. With dwarf dump I have all of information, but it is a mess...
This seems to work on your small sample. I'm not familiar with the format, so I've made an assumption of two here. It should be structured enough that you can extend it if you want to, even without know too much Perl.
Code:
#! /usr/bin/perl -w
#
# LQwebquinty.pl -- extract the good bits from dwarf output
#
# run as: LQwebquinty.pl <dwarffile.dat>
#
use strict;
my @variables;
$/ = "<1>"; # Split input data into records delimited by the tag '<1>'
my $variable;
while( <> ){
# BIG assumption here: we assume that the variable name/address
# field always precedes the respective type information.
#
if( $_ =~ m/DW_TAG_variable/ ){
$variable = variable->new( $_ );
push @variables, $variable;
}
elsif( $_ =~ m/DW_TAG_typedef/ ){
$variable->typedef( $_ );
}
elsif( $_ =~ m/DW_TAG_base_type/ ){
$variable->basetype( $_ );
}
}
print " Name Address Type (typedef....)\n";
foreach my $variable ( @variables ){
my $typedefs = join( ", ", @{$variable->{typedef}} );
print $variable->{name}, "\t", $variable->{address}, "\t",
$variable->{base_type}, "(", $typedefs,")\n";
}
package variable;
sub new{
my $proto = shift;
my $class = ref( $proto ) || $proto;
my $variableFields = shift;
my $self = {};
$self -> {name} = "";
$self -> {base_type} = "";
$self -> {typedef} = [];
$self -> {address} = "";
bless $self, $class;
my @variableFields = split( /\n/, $variableFields );
foreach my $variableField ( @variableFields ) {
if( $variableField =~ m/DW_AT_name/ ){
my @variableFieldParts = split( /:/, $variableField );
$self -> {name} = $variableFieldParts[-1];
# print "Found name: ", $self->{name},"\n";
}
if( $variableField =~ m/DW_AT_location/ ){
my @variableFieldParts = split( /:/, $variableField );
my $address = $variableFieldParts[-1];
$address =~ s/[^\d]//g;
$self -> {address} = $address;
# print "Found address: ", $self->{address},"\n";
}
}
return $self;
}
sub typedef($){
my $self = shift;
my $dwarfRecord = shift;
my @dwarfFields = split( /\n/, $dwarfRecord );
foreach my $field ( @dwarfFields ){
if( $field =~ m/DW_AT_name/ ){
my @fieldParts = split( /:/, $field );
# print "typedef: $fieldParts[-1]\n";
push @{$self->{typedef}}, $fieldParts[-1];
}
}
return $self->{typedef};
}
sub basetype($){
my $self = shift;
if( $_ ){
my $dwarfRecord = shift;
my @dwarfFields = split( /\n/, $dwarfRecord );
foreach my $field ( @dwarfFields ){
if( $field =~ m/DW_AT_name/ ){
my @fieldParts = split( /:/, $field );
# print "basetype: $fieldParts[-1]\n";
$self->{base_type} = $fieldParts[-1];
}
}
}
return $self->{base_type};
}
1;
Yes, that is the idea but, I could see that it is necessary to make a specific parser.
Thanks a lot for perl program, it works fine but I dont known perl lenguage.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.