Closed kryne001 closed 10 years ago
I can't tell what your error means from the information you've given. When you're reporting error messages, you should give the ENTIRE output of the program. Even if that means 10000 lines.
I suspect, however, that the error is actually happening on line 56 when you call execv
. Have you double checked that the contents of directory
(a very bad variable name btw) actually holds a command?
this is my entire run in gdb:
Starting program: /Users/evelynlocayon/rshell/rshell/a.out $ c
Breakpoint 1, main () at hw1.cpp:53 53 int pid = fork(); (gdb) step darwin_wait: ill-formatted message (id=0x961) wait kill ^C Program received signal SIGINT, Interrupt. 0x00007fff92b1be22 in ?? () (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y
Starting program: /Users/evelynlocayon/rshell/rshell/a.out $ ls
Breakpoint 1, main () at hw1.cpp:53 53 int pid = fork(); (gdb) step darwin_wait: ill-formatted message (id=0x961)
Here is a post that talks about what a bus error is. http://stackoverflow.com/questions/212466/what-is-a-bus-error
i read the stack overflow page, but i don't see how i'm using the wrong address for execv? unless i can't use one of those variables for the arguments?
i changed my code, pushed the update onto the same repository. my whole gdb error message is:
Starting program: /Users/evelynlocayon/rshell/rshell/a.out $ ls
Breakpoint 1, main () at hw1.cpp:54 54 int pid = fork(); (gdb) print targetDirectory $1 = 0x100006e28 "/usr/bin" (gdb) c Continuing. execv failed: Permission denied a.out(1730,0x7fff77e33310) malloc: * error for object 0x7fff5fbff551: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug
Program received signal SIGABRT, Aborted. 0x00007fff92b1b866 in ?? ()
@kryne001 I still suspect that there might be a problem with your directory
variable because you never actually display the value in your debug session. So you can't be certain that the variable contains what you want it to unless you print it!
Also, I see that you're running on a Mac and not on the lab machines. Remeber that Mac is a different flavor of Unix and so might behave slightly differently in different situations. Your final product must work on the CentOS installed on the lab machines.
Edit: Based on your latest post, the error message says you're calling free
on a pointer you haven't allocated with malloc
.
Looks like you are having an issue when allocating memory. Are you allocating the correct amount of memory when using malloc?
yeah i just ran gdb again and printed commands[0]. before it said "ls" but now it says "no commands in current context"
from what you can see, am i not allocating commands correctly? i allocated commands first based on the size of my commandLine string(which holds the entire line of user input), then used a loop to allocate then initialize each index in the array.
I'm getting the error: 'bus error: 10' when i run my code. I debugged and stepped through my code and when i reached line 55 in my code, i don't know if my code freezed or not but it looked like an infinite loop. however there's no loop started on that line. I called fork two lines earlier and i was able to step to the next line, so i don't know if that's the problem.
my code: https://github.com/kryne001/rshell/