Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example in the book does not work #7

Open
AlexanderKoshkarov opened this issue Aug 4, 2017 · 0 comments
Open

example in the book does not work #7

AlexanderKoshkarov opened this issue Aug 4, 2017 · 0 comments

Comments

@AlexanderKoshkarov
Copy link

Hello,
I started to read your book - it is nice! Thanks for it.
I stuck with gdb, where your examples on page 45 (GDB Variables) do not work for me. maybe I have too new version? (I downgraded gcc, but gdb my distro does not have packaged gdb lower then 7)
In short I cannot use "*x@3" for an array, here is a self explanatory log

[nix-shell:~/Downloads/test]$ gcc --version
gcc (GCC) 5.4.0
[nix-shell:~/Downloads/test]$ gdb --version
GNU gdb (GDB) 7.12.1
[nix-shell:~/Downloads/test]$ cat test.c
int main() {
    int x[20] = {};
    x[0] = 3;
}
[nix-shell:~/Downloads/test]$ gcc -O0 -g -Wall -std=gnu11 test.c
warning about not using x
[nix-shell:~/Downloads/test]$ gdb a.out 
(gdb) b 4
Breakpoint 1 at 0x400530: file test.c, line 4.
(gdb) r
Starting program: /home/kosh/Downloads/test/a.out 

Breakpoint 1, main () at test.c:4
4	}
(gdb) set $ptr=&x[3]
Attempt to take address of value not located in memory.
(gdb) p x
$1 = {3, <optimized out> <repeats 19 times>}
(gdb) p *x
Attempt to take address of value not located in memory.
(gdb) p *x@1
Attempt to take address of value not located in memory.
(gdb) p x[1]
$2 = <optimized out>
(gdb) p x[0]
$3 = 3

Is the problem with new gdb?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant