[DynInst_API:] Displaying local variables from an inserted Snippet


Date: Wed, 01 Jul 2015 19:22:52 +0000
From: "Rogers, Kelly K" <Kelly.Rogers@xxxxxxxxxxxx>
Subject: [DynInst_API:] Displaying local variables from an inserted Snippet

Hello,

 

I’ve been working on inserting snippets to running processes and displaying certain information using these snippets, such as the function, line number, and file name of where it is being inserted as well as the timestamp, pid of the process, a supplied text string, and certain local variables if they are in scope at this point. I have the Following as a simple example:

The sample program is this:

-----------------------------------------------------------------------------

void print_iteration(int value)

{

    int i = value;

 

//THIS IS WHERE I AM INSERTING THE SNIPPET TO DISPLAY THE INFORMATION

}

 

int main(int argc, char **argv) {

    int a;

    a = atoi(argv[1]);

    std::cout << "Performing " << a << " iterations." << std::endl;

 

    sleep(20);

 

    for(; a>0; --a)

    {

        print_iteration(a);

    }

    return 0;

}

-----------------------------------------------------------------------

Currently, this works and I am getting the following output:

 

~/Desktop/printf_IO # ./samp 5

 

Performing 5 iterations.

Filename: samp.c

Function: print_iteration

Line Number: 10

Timestamp: Wed Jul  1 11:56:25 2015

PID: 1684

hello

Variable: int i on line number 9 = 5

 

Filename: samp.c

Function: print_iteration

Line Number: 10

Timestamp: Wed Jul  1 11:56:25 2015

PID: 1684

hello

Variable: int i on line number 9 = 4

 

Filename: samp.c

Function: print_iteration

Line Number: 10

Timestamp: Wed Jul  1 11:56:25 2015

PID: 1684

hello

Variable: int i on line number 9 = 3

 

Filename: samp.c

Function: print_iteration

Line Number: 10

Timestamp: Wed Jul  1 11:56:25 2015

PID: 1684

hello

Variable: int i on line number 9 = 2

 

Filename: samp.c

Function: print_iteration

Line Number: 10

Timestamp: Wed Jul  1 11:56:25 2015

PID: 1684

hello

Variable: int i on line number 9 = 1

 

~/Desktop/printf_IO #

----------------------------------------------------------------------------------

When printing the line with the Variable information, I’m simply creating a funcCallExpr with a printf function call, supplying the string “Variable:  <type> x on line number y  = %<type>” and then supplying the BPatch_variableExpr, which is a subclass of type snippet, that I got from calling function->findVar(“i”), as arguments to the printf call, then inserting the snippet.

 

At this point, it all seems to be working correctly.  The problem arrises when my sample program has multiple local variables and I try to display all their values.  The following happens:

 

Here is the new sample code:

--------------------------------------------------------------------------------

void print_iteration(int value)

{

 

    int i = value;

    int j = i+2;

    int k = i-2;

 

//I AM INSERTING SNIPPET HERE

}

 

int main(int argc, char **argv) {

    int a;

    a = atoi(argv[1]);

    std::cout << "Performing " << a << " iterations." << std::endl;

 

    sleep(20);

 

    for(; a>0; --a)

    {

        print_iteration(a);

    }

    return 0;

}

 

--------------------------------------------------------------------------

And this is the new output:

 

~/Desktop/printf_IO # ./samp 5

Performing 5 iterations.

Filename: samp.c

Function: print_iteration

Line Number: 12

Timestamp: Wed Jul  1 12:17:43 2015

PID: 2666

hello

Variable: int i on line number 9 = 32767

Variable: int j on line number 10 = 0

Variable: int k on line number 11 = 5

 

Filename: samp.c

Function: print_iteration

Line Number: 12

Timestamp: Wed Jul  1 12:17:43 2015

PID: 2666

hello

Variable: int i on line number 9 = 32767

Variable: int j on line number 10 = 0

Variable: int k on line number 11 = 4

 

Filename: samp.c

Function: print_iteration

Line Number: 12

Timestamp: Wed Jul  1 12:17:43 2015

PID: 2666

hello

Variable: int i on line number 9 = 32767

Variable: int j on line number 10 = 0

Variable: int k on line number 11 = 3

 

Filename: samp.c

Function: print_iteration

Line Number: 12

Timestamp: Wed Jul  1 12:17:43 2015

PID: 2666

hello

Variable: int i on line number 9 = 32767

Variable: int j on line number 10 = 0

Variable: int k on line number 11 = 2

 

Filename: samp.c

Function: print_iteration

Line Number: 12

Timestamp: Wed Jul  1 12:17:43 2015

PID: 2666

hello

Variable: int i on line number 9 = 32767

Variable: int j on line number 10 = 0

Variable: int k on line number 11 = 1

 

~/Desktop/printf_IO #

 

------------------------------------------------

As you can see, the values for the variables are not correct.  The value of i is garbage, the value of j is always 0 and the value of k is showing as what the value of I should be.

 

Are the dyninst APIs handling BPatch_variableExpr’s correctly? Or is there another way I should be looking at to try to print the values of local variables from an inserted snippet? Or has there been any work/investigation/experimentation  already done regarding trying to do something like this?

 

Any help with this issue would greatly be appreciated.

 

Regards,

Kelly

[← Prev in Thread] Current Thread [Next in Thread→]