Hot answers tagged

25 votes

How to Check Sort Function with GDB

This can be tricky. I'll explain how to use GDB, and then show another way. GDB The commands below should be entered in a terminal window. First, compile your program using make, then run GDB and ...
user avatar
  • 2,625
17 votes

Surprise with GDB way of reading bfType BMP headers

bfType is an unsigned 16 bit integer (ie, 2 bytes long, aka a WORD). What you are seeing is the fact that xxd displays byte by byte, but gdb displays the word. So why does it matter? Intel ...
user avatar
  • 18.3k
3 votes
Accepted

How do you pass arguments into GDB argv[1] argv[2]?

To run GDB with arguments in the terminal, use the --args parameter. gdb --args name arg1 arg2 arg3 debug50 (the graphical debugger) is just GDB with a GUI. GDB was originally designed to be run ...
user avatar
  • 1,223
2 votes

GDB stops at GetInt()

I just solved this problem. I watched a GDB short by Nate Hardison from previous lectures and I found out that we were running a different command for using GDB. For Game of Fifteen, I was using "gdb -...
user avatar
2 votes
Accepted

<value optimized> GDB self optimizing everything

"This is a bug in clang, which has been fixed in version 3.5. The CS50 team is working on getting an update out with update50." -see link Variable optimized out eventhough it will be used later
user avatar
2 votes
Accepted

Check function skipping the check and returning all words as misspelled

print thisNode->word $2 = "elephant\n" Looks like you are including the new line char in your word. This will cause all of the words to be misspelled, as the word sent to check will, of course, ...
user avatar
  • 18.3k
2 votes
Accepted

pset 3 GDB: "no executable file specified"

To debug "find" with gdb, enter the following command: gdb find You need to enter the filename of the executable as a parameter following gdb on the command line. Don't use ./ or .c when you enter ...
user avatar
  • 63.1k
2 votes
Accepted

Variable optimized out eventhough it will be used later

This is a bug in clang, which has been fixed in version 3.5. The CS50 team is working on getting an update out with update50.
user avatar
  • 425
2 votes
Accepted

Debugging a program using command line arguments

See the image below: Note the command window. After I ran "Debug" once, I had to add the command-line argument "bacon" in order to get vigenere to run. I can simply edit the command box with any ...
user avatar
  • 1,424
1 vote

How to view global variable state in GDB?

Type the variable name in the Watch Expressions section at the top.
user avatar
  • 5,172
1 vote
Accepted

GDB "No such file or directory" error

What does it say in the new terminal window after "Runner:"? I suspect it says "Shell Command" or "Auto". A ".c" file cannot run in the shell. Has it been a while since you tried this? There used to ...
user avatar
1 vote
Accepted

Pset6 - Error With Using GDB

We have a serious problem at the very beginning. char* method_str = ""; I guess you want to write a blank, so write it for real. The lack of white space can cause segfault, or a strange behavior of ...
user avatar
  • 5,172
1 vote
Accepted

Pset6 - Help testing in gdb

Nevermind. I figured it out by rereading the course material and an answer to a previous question. Here is how: 1) type "gdb ./server" in your terminal window. 2) type "break parse" a the (gdb) ...
user avatar
1 vote

Pset6: How to debug load() and indexes()?

Here's what I do. Use debug50 instead of the command line gdb. If you haven't used that before: Run update50 to be sure you are up to date (the IDE is on version 81 at the moment). Then, here's ...
user avatar
  • 18.3k
1 vote

how to pass command line arguements in gdb

I couldn't get the hang of the ide50 debugger either. Launch gdb like: gdb whodunit Then to run: r file1.bmp file2.bmp In case you have more gdb related questions in the future, I use this site, ...
user avatar
1 vote
Accepted

pset6 parse: char* pointers are right in parse but return wrong value

Notice the difference between the declaration of abs_path/query in main char abs_path[LimitRequestLine + 1]; char query[LimitRequestLine + 1]; vs. the declaration in parse. bool parse(const char* ...
user avatar
1 vote
Accepted

How to pipe PRNg into find.c debug GUI?

I don't think anyone has figured that one out. It may not be possible, but I would be happy for someone to prove me wrong. OTOH, why do you want to work with so much input data in the debugger? ...
user avatar
  • 63.1k
1 vote

How to use GDB at not main program?

For my example, "mainP.c" will be our main program, and "secondP.c" will be your secondary file. I am assuming your "mainP" calls "secondP" at some time during the execution of the program. This is ...
user avatar
1 vote
Accepted

pset4 resize segmentation fault

The problem is here: if (isalpha(argv[1])) isalpha() takes a single char as input. argv[1] is a string. When you try to stuff a string into isalpha(), it chokes and seg faults. If this answers ...
user avatar
  • 63.1k
1 vote
Accepted

PSET5 - CHECK returning... nothing?

At the bottom of your code, there is a place where your function will not return anything. That's probably around line 93 in your program, the line that clang complained about. Now you need to follow ...
user avatar
1 vote

killing all inferior GDB Get's stuck

If you have been using breakpoints, and you don't want to continue using the same breakpoint use the command delete and all of your breakpoints will be deleted. If you only want to delete 1 breakpoint,...
user avatar
  • 23
1 vote

How to jump to a specific line in gdb

I would break the line that I want to jump to and continue. Watch the short on gdb for more info!
user avatar
  • 17.4k
1 vote
Accepted

gdb piping not working

If your program is called find do the following. make find gdb find break main run 65516 < testNumbers10000.txt next
user avatar
  • 7,326
1 vote

GDB: run a for loop x number of times

You can also use continue <n> to break only the Nth time the current breakpoint is hit, see also: https://stackoverflow.com/questions/2956889/how-to-make-a-gdb-breakpoint-only-break-after-the-...
user avatar
1 vote

GDB: run a for loop x number of times

You can put a counter in the loop and set a breakpoint based on the counter. For example, say you had this program: #includes go here ;-) int main(int argc, string argv[]) { for (int i=0; i<...
user avatar
  • 63.1k
1 vote

Determining location of file pointer in ascending bytes with GDB

since you've already assigned a variable to each of your pointers, you can print out their values at any time in gdb via: p in p out (p is shorthand for print)
user avatar
  • 1,415
1 vote

Debugging sort code

ok... As I see it, your outer loop should only execute once. You actually fall in a pretty annoying situation where an absolutely valid and algorithmically correct piece of code is not doing what it ...
user avatar
1 vote
Accepted

fifteen.c : printf() not printing anything to the screen

Have you noticed that when the fifteen program starts up, the entire screen is cleared? Compare that to the other programs before this, which just display the output directly after the command line. ...
user avatar
  • 2,625
1 vote
Accepted

Importance of Debuggers

Learning how to debug your code is as important as learning to code. As your programs get larger and more complex, they'll usually contain many logical errors. Unfortunately, compilers can't detect ...
user avatar
  • 17.4k
1 vote
Accepted

Why doesn't GDB work?

Program names are case-sensitive in Linux. Try gdb instead and that should work.
user avatar
  • 18.3k

Only top scored, non community-wiki answers of a minimum length are eligible