top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

With gdb how can you change the value of variable?

+4 votes
449 views

in case if is it possible, how you can change and pls explain with some example.

posted Sep 21, 2013 by Giri Prasad

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Say ur variable is a then

$gdb myprogram
Set a breakpoint on ur function say myfunc
gdb> b myfunc
gdb> r

Now program will stop at myfunc
Use p to print the variable

gdb> p a  ----- say value is 5 -----
gdb> 5
gdb> p a=8  ----- this will set the value as 8 -------
gdb> p a
gdb> 8
answer Sep 21, 2013 by Salil Agrawal
Similar Questions
+4 votes

Assume we have three threads and in this case how can we change the priority of threads. If it is possible then please explain with example.

+1 vote

I eager to know how watch point works in detail ?

+5 votes

Even I have similar problem:

int (*pfun)(void);
int *pInt = 0;
void fun1()
{
    int i = 5; /* Local to fun1*/

    printf("Outer function");
    pInt = &i; /* As I know address of local variable is valid till function execution */

    int fun2()
    {
      printf("innerfunction");
      printf("%d", *pInt);
    }
    /* fun2 address assign to pfun so that It can be called even after completion of fun1 */
    pfun = fun2;
}

int main()
{
    fun1();
    pfun();
    return 0;
}

Can someone please explain ? I am getting *pInt value 5.

+1 vote

As far as I know, CORE file contains all the information till Segmentation fault. Then, while debugging core file why we are using executable file(binary) with it.?

+1 vote

I am working on some JIT compiler and I am using GDB to debut it, my code crashes at some point (segment fault), but it crashes at the jitted code (they are generated on the fly) so I do not get the stack frame information, But I got the following backtrace:

#0 0x**********d98f22 in ?? () // JITTED CODE
#1 0x000000000000001d in ?? () // JITTED CODE
#2 ...callattribuite function....

I am wondering if it is possible for GDB to disassemble the code at location 0x**********d98f22 and display it to me. I tried disas 0x**********d98f22 but GDB complained No function contains specified address.

Any clue?

...