Results 1 to 10 of 10
I just wrote a simple Hello world program in C (my Linux distro is Fedora 5) and it ran well when built: gcc -g hello.c -o hello .
But when ...
- 11-13-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Error while debugging in Fedora
I just wrote a simple Hello world program in C (my Linux distro is Fedora 5) and it ran well when built: gcc -g hello.c -o hello .
But when I try to debug it as follow
Is that an error of Fedora 5 's gdb ?Code:debug hello set args a b c b 4 show args // a b c r p argc // Error !!!???
- 11-13-2007 #2
I'm having a difficult time making sense of some of your gdb commands.
- If your hello world program is small, please post the complete program source.
- Please post the command you used to compile the program.
- Please post the exact error message you got from gdb.
--
Bill
Old age and treachery will overcome youth and skill.
- 11-13-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Sorry,here is the source
That's all.Code:#include<stdio.h> int main() { printf("Hello world"); return 0; }
And the error message is
Cannot access memory at address 0x0
- 11-13-2007 #4
I'm using Slackware 9.1, not Fedora, but when I run this script:
I get this as output:Code:#!/bin/bash cat > hello.c <<EOD #include<stdio.h> int main() { printf("Hello world"); return 0; } EOD gcc -Wall -g hello.c -o hello cat > gdb_commands <<EOD set args a b c b 4 r p argc EOD gdb -n -x gdb_commands hello
but when I run this script:Code:GNU gdb 5.3 Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-slackware-linux"... Breakpoint 1 at 0x804834c: file hello.c, line 4. Breakpoint 1, main () at hello.c:4 4 printf("Hello world"); gdb_commands:4: Error in sourced command file: No symbol "argc" in current context. (gdb)
I get this output:Code:#include<stdio.h> int main(int argc, char **argv) { printf("Hello world"); return 0; } EOD gcc -Wall -g hello.c -o hello cat > gdb_commands <<EOD set args a b c b 4 r p argc EOD gdb -n -x gdb_commands hello
Hope this helps.Code:GNU gdb 5.3 Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-slackware-linux"... Breakpoint 1 at 0x804834c: file hello.c, line 4. Breakpoint 1, main (argc=4, argv=0xbffff9a4) at hello.c:4 4 printf("Hello world"); $1 = 4 (gdb)--
Bill
Old age and treachery will overcome youth and skill.
- 11-13-2007 #5Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Omg,I forgot to type the int argc,char ** argv . In my source code , I did have those !!! I just forgot when posting here !
And besides,the error message is "cannot access memory at 0x0" (not "no .. in current context").
I must emphasize that I use Fedora 5 , and it leads to this error .
At my school,the version is FC 2 and I debugged(exactly these commands) well (just like you !)
I think the problem is FC 5 . It may seem weird to blame for the distro , but if someone is using FC 5,could you test it for me ?
- 11-13-2007 #6
So what happens when you copy and paste the following into a file, chmod that file to 700, and run it? Can you take the exact output from that and paste it into a reply to this thread?
Code:#!/bin/bash cat > hello.c <<EOD #include<stdio.h> int main(int argc, char **argv) { printf("Hello world"); return 0; } EOD gcc -Wall -g hello.c -o hello cat > gdb_commands <<EOD set args a b c b 4 r p argc EOD gdb -n -x gdb_commands hello--
Bill
Old age and treachery will overcome youth and skill.
- 11-13-2007 #7Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Here is the output
Code:./bame GNU gdb Red Hat Linux (6.3.0.0-1.134.fc5rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". Breakpoint 1 at 0x8048395: file hello.c, line 4. Breakpoint 1, main () at hello.c:4 4 printf("Hello world"); gdb_commands:4: Error in sourced command file: Cannot access memory at address 0x0 (gdb)
- 11-13-2007 #8
That's funny. If I wanted to see output like that, I'd have to run a script something like this:
which for obvious reasons gives me:Code:#!/bin/bash cat > hello.c <<EOD #include<stdio.h> int main(int argc, char **argv) { printf("Hello world"); return 0; } EOD gcc -Wall -g hello.c -o hello cat > gdb_commands <<EOD set args a b c b 4 r p *argv[argc] EOD gdb -n -x gdb_commands hello
I don't have the foggiest notion why you got the error you got with my previous script. I'm hoping someone else can jump in here.Code:GNU gdb 5.3 Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-slackware-linux"... Breakpoint 1 at 0x804834c: file hello.c, line 4. Breakpoint 1, main (argc=4, argv=0xbffff9a4) at hello.c:4 4 printf("Hello world"); gdb_commands:4: Error in sourced command file: Cannot access memory at address 0x0 (gdb)--
Bill
Old age and treachery will overcome youth and skill.
- 11-15-2007 #9Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Can someone help me plz
- 11-15-2007 #10If you ran the script I offered in post 6, and that script was running a stock (unmodified) compiler and assembler and linker and debugger, and you got the output you describe in post 7, then I'm going to go out on a limb here and say that there is something seriously wrong with your system.Can someone help me plz--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote