Timeline for How to Check Sort Function with GDB
Current License: CC BY-SA 3.0
18 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 26, 2016 at 0:23 | comment | added | Luke Van In |
You should be able to pass in numbers.txt when entering the run command inside gdb, e.g. (gdb) run < numbers.txt . Alternatively you can use a named pipe to feed in the output of generate, see here: stackoverflow.com/questions/1456253/gdb-debugging-with-pipe
|
|
Mar 24, 2016 at 20:25 | comment | added | Dr.Queso | This is a great answer for general debugging, but the keyword that brought me here is "piping." I was hoping to see how to use piping within debugger, eg, instead of entering 100 numbers into the "find" function, simply pass it < numbers.txt, or pipe ./generate 100 || ./find 50... if that makes sense. I'll keep looking! | |
Jul 6, 2015 at 12:29 | comment | added | Joey Beaudette | A link to this should be added to the pset3 pdf p.16. Great explanation thanks. | |
Feb 16, 2015 at 22:24 | comment | added | daniel | I am completely lost when I do what you said it gives me: Breakpoint 1, 0x08048556 in sort () (gdb) list 1 dl-debug.c: No such file or directory. | |
Aug 24, 2014 at 0:04 | comment | added | Azurespot | Great thanks Luke :) | |
Aug 23, 2014 at 23:59 | comment | added | Luke Van In | That's a good candidate for a new question as there's not really enough space to show an example here, but the rule is: Functions need to be defined before they can be called. It is possible to use a "forward" declaration, which means you write just the function signature without the body, and then later on in the code include the whole function. | |
Aug 23, 2014 at 23:30 | comment | added | Azurespot | That's great, I will try that, thanks Luke. My only other question is, with C, what order do I write the functions in? I am used to object oriented, where you can write the function anywhere in your int main{} so long as you call it in the right place. Does the function itself have to be made anywhere above the place where you call it? | |
Aug 22, 2014 at 9:15 | comment | added | Luke Van In | I have updated the answer with an example on how to use the code. Note that the actual sorting in the example is done in a separate function which is you will need to write. In the example it's doing a bubble sort, but you can use whatever works for you. | |
Aug 22, 2014 at 9:14 | history | edited | Luke Van In | CC BY-SA 3.0 |
Added detailed example usage of check_sorted() and print_values().
|
Aug 22, 2014 at 8:32 | comment | added | Azurespot | Actually that error just means I can't put a function inside of another function. | |
Aug 22, 2014 at 8:23 | comment | added | Azurespot |
Thanks Luke, gdb showed me the line bool check_sorted(int values[], int n) , but then I did not know what to do with that. How to print any value from it. But then I realized I had to still make find even though it's read-only (but it will compile my helpers.c ), and an error came up: error: function definition is not allowed here { . So now I'm not sure how to fix that. Another question tho, is there a way to just print the final sort? Or maybe that is the hard part. I couldn't think of where to put printf() statements to capture each sort... I am using selection sort.
|
|
Aug 22, 2014 at 8:18 | history | edited | Luke Van In | CC BY-SA 3.0 |
Added example for testing sorted values.
|
Aug 22, 2014 at 8:14 | comment | added | Luke Van In |
Thanks for that, the answer has been corrected. Was check_sorted it actually skipped over, or was the code just not doing anything with the result from check_sorted ? I have added some code for printing the values once they're sorted. You can also use a printf statement inside the sort loop, but the output may not make sense, depending on the sort algorithm used.
|
|
Aug 22, 2014 at 8:08 | history | edited | Luke Van In | CC BY-SA 3.0 |
Corrected case of 'gdb' command. Added code for printing sorted values.
|
Aug 22, 2014 at 8:02 | history | edited | Luke Van In | CC BY-SA 3.0 |
Correct case of 'GDB' command - minor edit but critical.
|
Aug 22, 2014 at 7:58 | comment | added | Azurespot |
Thanks for this! Except I could not run GDB ./find , it had to be gdb ./find . Question though, I tried to insert your check_sorted() function right after my sort() main code (before the last curly brace and return; ) and then ran gdb, and it was skipped when I got there. Do you know why? I tried using the gdb regular way, and it seemed like values were in their right places, but they were all over the place, even in a simple 5 number list... so it was really hard to follow. Is there a super simple way to just print out the sorted list as it gets created? Thanks if you know.
|
|
Aug 2, 2014 at 21:15 | history | edited | Luke Van In | CC BY-SA 3.0 |
Added test functions and unit tests
|
Aug 2, 2014 at 20:53 | history | answered | Luke Van In | CC BY-SA 3.0 |