LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-10-2011, 03:48 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Rep: Reputation: 32
Extract dwarf information debug a section


Hello,

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...

Quote:
<1><117bc>: Abbrev Number: 32 (DW_TAG_variable)
<117bd> DW_AT_name : (indirect string, offset: 0x153d): draw_limits
<117c1> DW_AT_decl_file : 128
<117c2> DW_AT_decl_line : 207
<117c3> DW_AT_type : <0x1179a>
<117c7> DW_AT_external : 1
<117c8> DW_AT_location : 5 byte block: 3 72 32 7 8 (DW_OP_addr: 8073272)
<1><117ce>: Abbrev Number: 32 (DW_TAG_variable)
<117cf> DW_AT_name : (indirect string, offset: 0x15cd): step
<117d3> DW_AT_decl_file : 128
<117d4> DW_AT_decl_line : 209
<117d5> DW_AT_type : <0x10139>
<117d9> DW_AT_external : 1
<117da> DW_AT_location : 5 byte block: 3 7a 32 7 8 (DW_OP_addr: 807327a)
Is there any parser or way to put in order this information??

My idea is create a file with the follow information:

name of var - address - type - size - struct or not

Best regards
John Martin

Last edited by webquinty; 05-17-2011 at 07:45 AM.
 
Old 05-17-2011, 07:45 AM   #2
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Original Poster
Rep: Reputation: 32
Any advice?
 
Old 05-17-2011, 08:27 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
It looks rather orderly to me already. What exactly did you have in mind?
--- rod.
 
Old 05-17-2011, 10:32 AM   #4
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Original Poster
Rep: Reputation: 32
Hello theNbomr,

Well, dwarf give me all debug information, but it is a little bit difficult to understand debug information.

For example, variable name mode_counter:

Quote:
<1><173c7>: Abbrev Number: 24 (DW_TAG_variable)
<173c8> DW_AT_name : (indirect string, offset: 0x2144): mode_counter
<173cc> DW_AT_decl_file : 2
<173cd> DW_AT_decl_line : 160
<173ce> DW_AT_type : <0x15f3d>
<173d2> DW_AT_external : 1
<173d3> DW_AT_location : 5 byte block: 3 44 32 7 8 (DW_OP_addr: 8073244)

<1><15f3d>: Abbrev Number: 2 (DW_TAG_typedef)
<15f3e> DW_AT_name : (indirect string, offset: 0x2cd): BOOL
<15f42> DW_AT_decl_file : 3
<15f43> DW_AT_decl_line : 41
<15f44> DW_AT_type : <0x15f0b>

<1><15f0b>: Abbrev Number: 2 (DW_TAG_typedef)
<15f0c> DW_AT_name : (indirect string, offset: 0x19dd): plcbit
<15f10> DW_AT_decl_file : 3
<15f11> DW_AT_decl_line : 33
<15f12> DW_AT_type : <0x15f16>

<1><15f16>: Abbrev Number: 3 (DW_TAG_base_type)
<15f17> DW_AT_byte_size : 1
<15f18> DW_AT_encoding : 8 (unsigned char)
<15f19> DW_AT_name : (indirect string, offset: 0xf3): unsigned char

This is a dwarf definition of variable mode_counter, and I would like to create a file with the follow information:

Name ----------------- address ------------------ type
mode_counter --------- 0x8073244 ---------------- BOOL (plcbit,unsigned char)

Then, it is like a parser, to put in order information and understand more easy debug information.

Last edited by webquinty; 05-17-2011 at 10:35 AM.
 
Old 05-17-2011, 07:53 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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;
--- rod.
 
Old 05-19-2011, 05:17 AM   #6
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Original Poster
Rep: Reputation: 32
Hello theNbomr,

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.

Then, I am going to make it in java.

Thank you very much rod.
Best regards.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Perl extract information for a particular column kdelover Programming 7 10-26-2010 03:24 AM
[SOLVED] How to get Openssh sshd daemon debug information on Solaris 10? johncsl82 Solaris / OpenSolaris 3 09-01-2009 07:49 AM
How to obtain debug information from a section!!!!! webquinty Linux - Newbie 2 10-30-2008 04:23 AM
How to debug without having debug section in an executable ? unclesam Linux - Newbie 0 02-02-2006 06:23 AM
[debug]what does the following debug information mean icoming Programming 21 06-08-2004 02:13 AM


All times are GMT -5. The time now is 03:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration