Quick Intro to gdb

  Рет қаралды 199,221

MyGeekAdventures

MyGeekAdventures

Күн бұрын

Just a quick overview of some often-used gdb (and related) commands, including:
gcc -g to compile a program and include debugging information
start - begin exexuting your program
list - examine your source code from within the debugger
step - execute the next line of your program
next - execute the next line of your program, but if it's a subroutine call, treat the entire subroutine as a single line
print - examine the contents of a variable
x - examine memory directly
watch, rwatch - set a watch for when a variable is written or read: return to the debugger once this happens
break - set a breakpoint: return to the debugger when this line of code is about to be executed
info watch - show info on watchpoints
info break - show info on breakpoints
delete # - delete watchpoint or breakpoint "#"
cont - continue from a breakpoint, watchpoint, step, next, etc.; basically begin running your program from where it left off
set var name=value set the value of variable "name" to "value"
bt - show the call frames for your program
frame # - set the current frame to #. Variables you reference etc. will be those within that context.
quit - leave the debugger

Пікірлер: 232
@mrizigarouiass6474
@mrizigarouiass6474 8 жыл бұрын
This is a tutorial, clean, Not b*s talk, to the point, No background music. In 20 minutes you covered the main commands. My Bests, Thank you.
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
Thanks! I write it for some students who needed a quick overview, so I tried to stick to the main points. I appreciate the feedback!
@stickmaker10111
@stickmaker10111 7 жыл бұрын
Yeah I have to agree. There are a lot of 'b*s' tutorials. It isn't that bad, and they introduce you to a working example, but this gives a head on example of things to use. Me familiar with C, and never hearing of gdb, wanting to use this tool because for some reason I hear it was all good, a deterrent would be crappy tutorials.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Hey great, glad it worked for you and made sense! Thanks for the comment.
@stickmaker10111
@stickmaker10111 7 жыл бұрын
One quick question, would the p command execute functions? Ex: p cos(5)
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Polite Kiwi yes usually, though I believe you'd need to have linked in the math library when you compiled. You can even do things like p fopen(....) to open a file, etc. :)
@coudbook2177
@coudbook2177 4 жыл бұрын
Relevant gdb commands I've gathered over time: info gdb //Manual info locals //Vars in local scope info variables //Vars declared outside current scope info functions //Names and datatypes of all defined functions info b //List all breakpoints break funcName //Set breakpoint at function funcName (short: b funcName) break file::line //Set breakpoint at line in file layout next //Cycle through the layouts of gdb p var //Print the value of variable var p var = value //Force set value to a var run //Start the program start //Synonymous to (b main && run). Puts temporary b at main next //Execute the current line in source (short: n) step //Step into function call at current line (short: s) finish //Finish the execution of current function (short: fin) continue //Resume execution (After a breakpoint) (short: c) refresh //Repaint the interface (To fix corrupted interface) shell cmd //Run shell command cmd from gdb prompt python gdb.execute(cmd) //Run a gdb command cmd from python prompt set print pretty on //Enable pretty printing (Put in ~/.gdbinit) $ gdb -c core.num //Examine the dumped core file from a SIGSEGV(shell command) bt //Print backtrace break _exit //Breakpoint at exit of program whatis expr //Print datatype of expr ptype expr //Detailed print of datatype of expr watch var //Stop when var is modified watch -l foo //Watch foo loaction rwatch foo //Stop when foo is read watch foo if foo>10 //Watch foo conditionally delete //Delete all breakpoints delete breakpoint_no //Delete breakpoint breakpoint_no command breakpoint_no //Run user listed commands when breakpoint is hit (End list of commands with 'end') file executable //Load the executable for debugging from inside gdb quit //Quit (short: q) Feel free to correct/add any useful command you know.
@MyGeekAdventures
@MyGeekAdventures 4 жыл бұрын
Nice command summary - thanks!
@ErikZoltan
@ErikZoltan 6 жыл бұрын
This is an incredibly accessible and useful presentation of a powerful program that normally has a sharp learning curve. With this introduction, it is easy to get going immediately with gdb.
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
Thanks! That was really my goal, keep it simple and get people using gdb quickly. Thanks for the feedback!
@rockinronnie2
@rockinronnie2 9 жыл бұрын
I'm a beginner with C. This video was exactly what I needed to get started with gdb. Your demonstration by example was sooo much easier to understand than all the reading I tried. Thank you, thank you, thank you.
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
rockinronnie2 Oh cool, I'm glad it was helpful. Thanks for posting the comment!
@NaveenKrishnaCh
@NaveenKrishnaCh 10 жыл бұрын
quite useful, never thought gdb is so simple to start with
@jackm7096
@jackm7096 4 жыл бұрын
It's awesome! Thank you! Summary: list, start, quit, step, next, x, print/p, watch abc, cont, break 9, info watch, info break, bt (backtrace), set var sum=23
@MyGeekAdventures
@MyGeekAdventures 4 жыл бұрын
You're welcome. And good summary!
@mercedesbenzformula1
@mercedesbenzformula1 6 жыл бұрын
Thank you very much for this introduction! It was extremely informative and covered a lot of great features. I ended up watching it twice to really get it down. This has saved me a lot of time debugging my code
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
I'm glad to hear that! It takes a bit to get used to, but once you know it, it definitely saves time debugging :)
@insidetrip101
@insidetrip101 6 жыл бұрын
I wish that instead of just giving me an answer or marking my post as a duplicate, someone would have previously just made a link to this video. You've helped tremendously.
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
Great! Glad it helped, it's a useful tool to have in your bag of tricks :)
@okeowoaderemi
@okeowoaderemi 9 жыл бұрын
Wow this is awesome, thanks for the command "-g" with g++ i almost lost it when it didn't work the way it should
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
+Okeowo Aderemi Glad that helped. Yeah the littlest details sometimes cause the biggest headaches!
@d3magol9
@d3magol9 3 жыл бұрын
I couldn’t understand why numbers were used with the examine command, you explained and demonstrated it so well
@MyGeekAdventures
@MyGeekAdventures 3 жыл бұрын
Cool! Glad that makes sense now. "examine" is really useful to see what's going on at the lowest levels. Thanks for the note :)
@MrDubs
@MrDubs 4 жыл бұрын
gdb has always intimidated me. Today is the day I get over my fear of it. Edit: Just like that, 30 minutes later I've got breakpoints and various commands to control working through my program. Thank you!
@MyGeekAdventures
@MyGeekAdventures 4 жыл бұрын
Wow, that's great - congratulations! and thank you so much for letting me know, I really appreciate it :)
@themyxa
@themyxa 9 жыл бұрын
Really nice hands-on intro to gdb
@zihongzheng4317
@zihongzheng4317 9 жыл бұрын
This is definitely a great tutotial for GDB. Thanks
@shirleyachara3809
@shirleyachara3809 4 жыл бұрын
Very good explanation of gdb commands, thanks.
@MyGeekAdventures
@MyGeekAdventures 4 жыл бұрын
You're welcome - have fun :)
@ConcealedSteel
@ConcealedSteel 6 ай бұрын
Excellent, information rich content. Well done.
@MyGeekAdventures
@MyGeekAdventures 6 ай бұрын
@@ConcealedSteel Thanks! Glad it was helpful, and I appreciate the comments.
@charlamenanc6264
@charlamenanc6264 7 жыл бұрын
Thanks a lot .I just started using gdb.Your tutorial helped to start with.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Great! Good luck with gdb!
@n3los
@n3los 9 жыл бұрын
what a well explained use of GDB. thanks for the time you spent on video.
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
Daniel Castillo You're welcome - glad if it helped!
@bitbuster512
@bitbuster512 6 жыл бұрын
20 minutes well spent. thanx.
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
Roman Pfneudl Thanks for saying so!
@grovestreet9165
@grovestreet9165 7 жыл бұрын
Best video tutorial for debugg
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Thanks! Hope it was helpful...
@stevensiwinski
@stevensiwinski 11 жыл бұрын
This was incredibly useful to me as a starting point. Thanks!
@ezellburke
@ezellburke 10 жыл бұрын
Great Tutorial, looking forward to more
@deeplyembedded9548
@deeplyembedded9548 7 жыл бұрын
I would like to seek your permission to share your tutorial video on my Blog. It is the best I have seen for learning how to debug using gdb. Very helpful for Firmware Engineers like me. Thank you.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
DeeplyEmbedded Sure, that would be fine with me (thanks for asking). Glad it seems helpful :)
@engineerzhub538
@engineerzhub538 7 жыл бұрын
You can also check out the kinds of stuff I do on my geeky weekends, it may be of interest to you. Feel free to check out my blog www.deeplyembedded.org/. It does have some good stuff to spice up your life :) Thanks.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Thanks for the link to your site - some interesting things you're doing! (I don't know why your comment didn't show up here though)
@deeplyembedded9548
@deeplyembedded9548 7 жыл бұрын
I have a joint account. One is EngineerzHub and another is DeeplyEmbedded. The comment did not show up here may be because I did it using a different A/C. Anyways here you go, www.deeplyembedded.org/. Thanks :)
@aahasan1
@aahasan1 6 жыл бұрын
Awesome: Concise: Helpful: Perfect
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
Great! Thanks for letting me know, and very happy that it was helpful :)
@vadymoliinyk8068
@vadymoliinyk8068 10 жыл бұрын
Simple and useful . Thanks for video.
@TheSaravanan42
@TheSaravanan42 8 жыл бұрын
This tutorial is simple and great. Today learned some new commends :) Thank you.
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
That's great! It's a really useful tool for debugging, also for learning how things work "under the hood." Thanks for the feedback!
@andrematias2430
@andrematias2430 10 жыл бұрын
Great video, you mention the really important goals :) Thanks!
@masterevill
@masterevill 6 жыл бұрын
Thanks for this intro! It was a big help.
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're welcome!
@Calderonf
@Calderonf 9 жыл бұрын
Thanks, Just wath I need to debug, no more no less a perfect tutorial!
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
Francisco Carlos Calderon Thanks! I appreciate the feedback :)
@danieljimenez1989
@danieljimenez1989 8 жыл бұрын
Nice video, many thanks! It comes in very handy to determine whether GDB is what you need or not. In my case, yes it is :D
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
Thanks, and that's awesome - gdb is very useful for some types of debugging, so it's good to know how to use it :)
@juvannetd
@juvannetd 8 жыл бұрын
Wow, that's really good presentation. Thanks.
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
You're welcome! Hope it was helpful. gdb rocks!
@localtraveller2102
@localtraveller2102 8 жыл бұрын
very good explanation. As you mentioned 20 things with gdb. May you please shot more videos on gdb with remaining 15 things or more.
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
Thanks. I may do more videos on gdb or other programming/debugging topics.
@localtraveller2102
@localtraveller2102 8 жыл бұрын
Thank you so much. I'm curiously waiting.
@Leo-ie5lx
@Leo-ie5lx 5 жыл бұрын
this is a great tutorial !!!! learn a lot from your tutorial thank you
@MyGeekAdventures
@MyGeekAdventures 5 жыл бұрын
Glad to hear it! You're welcome and thanks for letting me know :)
@CyberCrowBR
@CyberCrowBR 7 жыл бұрын
Nice !!! Congratulations from Brazil !!
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Thanks!
@pavelrahl6284
@pavelrahl6284 6 жыл бұрын
Keep being awesome. Thanks a lot for the tutorial.
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're welcome, and thanks for the awesome comment :) Cheers!
@clshanley
@clshanley 10 жыл бұрын
EXTREMELY helpful. Thanks so much!
@shikharmahajan7346
@shikharmahajan7346 7 жыл бұрын
wow, you still reply to the comments! Amazed
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Yay for email address longevity :)
@lordadamson
@lordadamson 9 жыл бұрын
Thanks a lot man. I hate bloated IDEs and I was thinking I'd use gdb directly. hopefully that will be practical in big projects.
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
+Adam Zahran Awesome - and yes, using the command line can be so much cleaner than IDEs. Thanks for the comment - enjoy :)
@BiggestNano
@BiggestNano 7 жыл бұрын
This was extremely useful. Thanks!
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Great, thanks for letting me know!
@ShankhashubhraDas12
@ShankhashubhraDas12 6 жыл бұрын
This video is well described. Thanks a lot.
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're very welcome! Hope it helped
@daniel1988evil
@daniel1988evil 8 жыл бұрын
Excellent video! Thank you!
@avinashmv9686894578
@avinashmv9686894578 5 жыл бұрын
Good job, nice tutorial. Thanks.
@MyGeekAdventures
@MyGeekAdventures 5 жыл бұрын
Thanks! Hope it helped :)
@jelenatrifkovic7128
@jelenatrifkovic7128 6 жыл бұрын
Thank you so much! Very clear explanation :)
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're welcome! gdb is a great tool, hope you find it useful :)
@BigBossLegna
@BigBossLegna 10 жыл бұрын
Thanks for ur time!!
@kanskejonasidag1
@kanskejonasidag1 7 жыл бұрын
Such a great video! Thanks!
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
You're welcome :)
@JSC-4
@JSC-4 4 жыл бұрын
Thanks for the great tutorial. This might be a obvious question, but is the same gdb that IDE's use to debug code? As in IDE's use a gui version of gdb as opposed to the terminal, that you've shown in the video?
@MyGeekAdventures
@MyGeekAdventures 4 жыл бұрын
You're welcome! So really good question, and mostly I don't know the answer. C under Eclipse may use gdb (I haven't tried), but I think some other IDEs probably use their own. A definitely for other languages IDEs may use their own debugger (e.g. MPLAB's front end for MPASM development uses their own debugger). But the general principles (breakpoints, examining memory, etc.) are largely the same.
@JSC-4
@JSC-4 4 жыл бұрын
@@MyGeekAdventures ahh ok, thanks for the reply!
@konstantinterziev9779
@konstantinterziev9779 7 жыл бұрын
Neat video. Thank you. Just a minor inconvenience. I pause a lot during the video and try the commands myself and the youtube controls (play button, volume, etc.) keep covering the bottom line. Anyway thanks again.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Oh that is a pain! Next time I'll slide the video up a bit. Thanks for the note :)
@kiddcode2848
@kiddcode2848 9 жыл бұрын
Great video!
@pratk9700
@pratk9700 8 жыл бұрын
Thanks for such brief but detailed intro. I am gonna try this with onlinegdb.com It would be helpful if you can make video on reverse debugging.
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
Haven't seen that site before, but it sounds interesting, thanks for the link. Glad this video was helpful.
@sk.razibulislam4493
@sk.razibulislam4493 9 жыл бұрын
perfect tutorial for gdb
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
SK. Razibul Islam Thanks, I appreciate the feedback!
@omardhona
@omardhona 9 жыл бұрын
Very helpful video thank you
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
Great! Glad it helped :)
@AtlasMTBRider
@AtlasMTBRider 6 жыл бұрын
great video, thank you .
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're welcome!
@jeison69
@jeison69 10 жыл бұрын
TY IT HELPED ME A LOT!
@MyGeekAdventures
@MyGeekAdventures 10 жыл бұрын
Awesome, glad it helped!
@malharjajoo6237
@malharjajoo6237 7 жыл бұрын
Great tutorial !
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Malhar Jajoo Thanks! Glad you liked it :)
@bakkasur9614
@bakkasur9614 8 жыл бұрын
awesome , i learned alot .
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
Great, glad to hear it!
@Halahamante
@Halahamante 4 жыл бұрын
subroutine is a name for a function in fortran, in normal languages functions are called functions
@MyGeekAdventures
@MyGeekAdventures 4 жыл бұрын
FORTRAN isn't a normal language? Lol
@guthivaralakshmiguthivaral2144
@guthivaralakshmiguthivaral2144 Жыл бұрын
Very useful video
@MyGeekAdventures
@MyGeekAdventures Жыл бұрын
Thanks! Glad it helped 🙂
@hxtbbsqwtu
@hxtbbsqwtu 9 жыл бұрын
great explanation! Thanks!
@Myriad00
@Myriad00 10 жыл бұрын
how would i include the steps at 2:04 in a makefile? i cant really find any useful documentation on it.
@MyGeekAdventures
@MyGeekAdventures 10 жыл бұрын
Here's a typical makefile for a program comprised of two .c files: program: program.o sub.o (this must be a tab, not a bunch of spaces) gcc -g -o program program.o sub.o program.o: program.c gcc -g -c program.c sub.o: sub.c gcc -h -c sub.c
@MyGeekAdventures
@MyGeekAdventures 10 жыл бұрын
MyGeekAdventures that last gcc is gcc -g not gcc -h
@superknife24
@superknife24 9 жыл бұрын
considering how the bytes in Hello are arranged at 10:41, is your machine little endian in byte ordering?
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
superknife24 Hmmm I'm not sure endian-ness applies to strings (character arrays), since each entry occupies only one byte and the ordering is almost certainly array[0] first, then array[1], etc. But were this an integer, like 16, stored as a 4-byte integer, and the ordering in memory was 16 00 00 00 then that would be little-endian (LSB stored in the lowest memory address).
@mandiciszilard
@mandiciszilard 9 жыл бұрын
superknife24 I think it is represented like this because of the fact that the array of characters is allocated on the stack and the stack grows from larger addresses to smaller addresses. It has nothing to do with endianess because of the fact that a character occupies 1 byte. As the author already suggested, it would be visible only when we use multi-byte data types like int.
@RayMillTN1
@RayMillTN1 10 жыл бұрын
very good video, thanks!
@FernandoBasso
@FernandoBasso 10 жыл бұрын
Very nice and useful video. Thanks a lot. What terminal emulator and OS are you using?
@MyGeekAdventures
@MyGeekAdventures 10 жыл бұрын
Thanks and you're welcome! This is Ubuntu (don't remember which version) running on a 3-4 year old laptop. The terminal window is just Ubuntu's standard "terminal" program.
@FernandoBasso
@FernandoBasso 10 жыл бұрын
MyGeekAdventures All right, thanks. It didn't look like Ubuntu since it is not the Ubuntu theme. By the way, don't hesitate on making more video lessons like this one. You are a great teacher and would really help a lot of people. Thanks once more.
@MyGeekAdventures
@MyGeekAdventures 10 жыл бұрын
Fernando Basso Thanks for the feedback. I may do some more videos: makefiles, KVL/KCL and linked lists may be my next topics :)
@FernandoBasso
@FernandoBasso 10 жыл бұрын
MyGeekAdventures Cool! Those are all interesting subjects. :)
@ronneilcamara5071
@ronneilcamara5071 11 жыл бұрын
Awesome tutorial! Is there a book or online link that I can learn more about gdb? Which book/link helped you learn gdb a lot?
@MegaFUNKTOPUS
@MegaFUNKTOPUS 10 жыл бұрын
Ronneil Camara I'm learning from Hacking: The art of exploitation, by Jon Erickson. Very good book which teaches you how to debug and complie C programs plus hack the shit out of them.
@MyGeekAdventures
@MyGeekAdventures 10 жыл бұрын
Sounds like a good book, though I haven't read it myself. One of the best ways to learn is by doing. Write some code, go into gdb, and start playing with it. Try new commands, practice, and explore what it can do :)
@Hitz9092
@Hitz9092 8 жыл бұрын
Thanks it was really helpful.
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
You're welcome - glad it was helpful :)
@EnduranceT
@EnduranceT 8 жыл бұрын
This video is heroic. Thanks so much! Are there any other related tools you'd recommend? I've heard of something called Valgrind but Im stuck on Windows so not sure if that's available.
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
Hey thanks! Yeah valgrind is useful as soon as you're messing with dynamic memory allocation (malloc etc.) It can help you find memory leaks, which can be tricky sometimes. It doesn't come with Cygwin, but there are other options even if you're stuck on Windows: you can install Virtualbox and then Ubuntu in there, and play with valgrind that way. There's also a Ubuntu/bash shell available in Windows 10 now, but it's beta, and mine stopped working recently. I hope to post a Makefile video this week, that's a very useful command too :)
@EnduranceT
@EnduranceT 8 жыл бұрын
Awesome, thanks again! Yeah make is another thing I haven't touched yet. I'm making the switch from C# to C so these types of things are unique to C but also very powerful!
@songpengzu4537
@songpengzu4537 10 жыл бұрын
Great~ BTW, you might add an explain of how to add parameters to your program when you use gdb.
@elginbeloy6205
@elginbeloy6205 3 жыл бұрын
"A higher level [language] program, such as one written in C" - I stand on the shoulders of giants as I write my little Python programs.
@MyGeekAdventures
@MyGeekAdventures 3 жыл бұрын
Nothing little about Python programs :) Rock on!
@gasubasu
@gasubasu 9 жыл бұрын
Thank you! Compact and usefull!
@vincentm99
@vincentm99 7 жыл бұрын
extremely helpful, thanks ; )
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
You're welcome :)
@segovialini
@segovialini 9 жыл бұрын
Great tutorial!!! You sound like Gilfoyle!!!
@nickmacias9104
@nickmacias9104 9 жыл бұрын
segovialini Thanks lol!
@danwat1234
@danwat1234 9 жыл бұрын
+segovialini Also a bit like James Garner
@djtoddles8750
@djtoddles8750 6 жыл бұрын
great stuff, thanks
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're welcome!
@tojo2sk8
@tojo2sk8 2 жыл бұрын
Por qué carj el título está en español
@sing759
@sing759 8 жыл бұрын
great tutorial ..thanks..
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
You're welcome! Glad it was helpful.
@CanMetan
@CanMetan 9 жыл бұрын
that helped a lot thanks.
@davidgerstgrasser8650
@davidgerstgrasser8650 4 жыл бұрын
legends say he is still replying
@MyGeekAdventures
@MyGeekAdventures 4 жыл бұрын
Lol legend also says people are still watching and commenting :)
@guilhermesouza8614
@guilhermesouza8614 8 жыл бұрын
Hi, What if my program has to do an extraction (std::cin) from the user... How do you do that while in GDB? I am using cygwin on windows. Very instructional video! Thanks!
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
The debugger should just pause while waiting for input. After you hit Enter it will continue with the next statement. But be careful not to accidentally step into a routine like fgets... Step *over* those to keep gdb from trying to debug system - level code
@aniketpagar2229
@aniketpagar2229 7 жыл бұрын
good work, thanks
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Aniket Pagar Thank you!
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Thanks, you're welcome :)
@syuanchengchen7488
@syuanchengchen7488 7 жыл бұрын
I typed "start", then "watch i", and then "step" for several times to go through for loop, but the "Old value" and "New value" message didn't show up, is there anything I missed? I'm using Ubuntu 16.04 (gdb version 7.11.1) on VMplayer 12.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Hi, a few thing to know about using watchpoints in gdb: (1) Watchpoints don't seem to fire when you say "step" or "next." Try using continue ("cont") and you should see them working. A watchpoint is really a way to pause program execution and return to debugging: since "step" and "next" cause these same actions, I guess the watchpoint is ignored; (2) Watchpoints seem to disappear after your program terminates. Whenever you say "start" you need to re-say "watch i" (there's probably a way to make the watch more persistent) (3) If you've been single-stepping and then say "cont," the first reported change to your watched variable may have an incorrect OLD value. This is from tests on gdb 7.11.1 on Ubuntu 16.04.
@syuanchengchen7488
@syuanchengchen7488 7 жыл бұрын
Many thanks to the reply! I have used "watch" together with "cont" and it works fine for me. However, I was unable to reproduce the situation starting from 12:10 of this tutorial, which you used "watch i" and then "step" to invoke the watchpoint messages. Could you reproduce this situation on gdb 7.11.1? Here's some things I've tried so far: 1. I've tried to install the latest verions of Ubuntu, Mint, and eOS on VMplayer and test if "watch i + steps" works, but all of them were failed. 2. I've run the test.c on this gdb online tool(www.onlinegdb.com/), and "watch i + steps" works fine! 3. I've build an Ubuntu 16.04 server by using Amazon EC2, installing gdb 7.11.1 to test, and this time it works! "Old value =" and "New value =" will appear when I use "watch i + steps". Not sure if it's the problem of VM, did you also test it on a VM? Thank you.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Hi again, I think I'm running this on a VM (it's a pay-for server). It used to work as in the video, but seems to behave differently now. You can say display i and that should display the value of i each time it stops (including after each step). Cheers, -Nick
@syuanchengchen7488
@syuanchengchen7488 7 жыл бұрын
"display i" also works great. Thank you for resolving my doubt.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Awesome, glad to hear it works :)
@TheManumanohar
@TheManumanohar 9 жыл бұрын
when I use start in lldb it shows the following output error: 'start' is not a valid command. why is that so?
@MyGeekAdventures
@MyGeekAdventures 9 жыл бұрын
Hi, I haven't used lldb but it looks like its commands are very similar to gdb's. Try just using run instead of start. lldb.llvm.org/lldb-gdb.html shows a list of equivalences between gdb and lldb. Cheers, - Nick
@reymicroc
@reymicroc 6 жыл бұрын
can you print the value of an element of an array by just using print A[i, j]?
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
That's a really good, very simple question, with a very complex answer! The short answer is yes and no lol. First though note that I'd usually access an element by A[i][j] instead of A[i,j]. In some cases you can do this, for example, in this code: (gdb) list 1 #include 2 main() 3 { 4 int x[4][4]; 5 for (int i=0;i
@SeshachalamMalisetti
@SeshachalamMalisetti 6 жыл бұрын
Since when the step is going to the subroutine that we have not written ?
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
Hello, I'm not sure I understand your question, but this may be related. When you say "next" right before a function call, it executes the function, but doesn't return control to you until that function exits. This is normally what you'd do before calling a function you don't want to debug. But if you say "step" then it lets you debug the function that was called. If that's a function like printf() or sqrt(), you'll now find yourself in the middle of code you didn't write, and gdb will sometimes seem to behave badly. The best solution is to use "next" before function calls (unless you want to debug the function). If you accidentally say "step" and want to get out of the function, the command "finish" will (usually) finish running the function's code and then return control to you, as if you had said next instead of step. Don't know if that addresses your question or not; if not, can you ask again?
@SeshachalamMalisetti
@SeshachalamMalisetti 6 жыл бұрын
the first paragraph answered my question. when i try to debug my hello world binary, step takes me to IO_puts (str=0x5555555546f4 "Hello, world!") at ioputs.c:33. thanks for the reply. I understood the video tutorial. what do you do, If i may ask.
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
Ah cool, glad that made sense. > what do you do, If i may ask. I teach at Clark College, and I have a small research company (Cell Matrix Corporation) among other things :)
@sarbajitg
@sarbajitg 5 жыл бұрын
The we view the contents of instruction register (not instruction pointer !!!!!) Using GDB.
@pureXtactics
@pureXtactics 11 жыл бұрын
Bro! i really need to find out how to even do this. If i write GDB test NOTHING HAPPENS! Help :(
@Anveshana837
@Anveshana837 7 жыл бұрын
Step doesn't seem to work in my linux system (ubuntu 16.04) , it always gives an error related to printf.....
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Does "next" work? step is like next, but actually moves inside functions. So if you're about to execute a printf(...) and you say step, it will start trying to debug the printf function itself, which generates confusing output and error messages. If you use next, it will complete the call to printf and the return to your program, and then wait for you (which is usually what one wants). Sometimes the command "finish" will get you out of a confusing "step" but your best bet is to always use next unless you really want to step *inside* a function you're about to call.
@huyvole9724
@huyvole9724 6 жыл бұрын
Thanks. What is your distro/name OS?
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're welcome! I don't remember what I was using back then, some variant of Ubuntu? Right now I'm on XUbuntu 18.04 + Xfce
@huyvole9724
@huyvole9724 6 жыл бұрын
@@MyGeekAdventures Simple OS, thank you sir. I have a question, I have array[100], for each element of array I have solution with this but I want to see the result of array[100], I have to type "next" (x100 times). Can I have any solution to quick loop to see my result?
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
@@huyvole9724 Well, if you declare an array like int array[100]. then the command p array should show you the entire array. For example: (gdb) list 1 int main() 2 { 3 int array[100]; 4 for (int i=0;i
@huyvole9724
@huyvole9724 6 жыл бұрын
@@MyGeekAdventures Oh my god use "break" to jump, thank you so much. I only think "next" without "break"
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
@@huyvole9724 Ah yeah you're welcome - break is really useful :)
@strawberryPlasma
@strawberryPlasma 7 жыл бұрын
thank you!
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Yana Osipov Hey, you're very welcome! Glad it helped.
@MiNombreEsGabo
@MiNombreEsGabo 8 жыл бұрын
wich shell do you use?
@MyGeekAdventures
@MyGeekAdventures 8 жыл бұрын
I think I was using tcsh at the time.
@victormarciliopeixoto
@victormarciliopeixoto 10 жыл бұрын
nice tutorial! ;)
@collinsedward3156
@collinsedward3156 7 жыл бұрын
How do I create the ~/.gdbinit file?
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
Hmmm do you mean what do you put in it, or how do you create it? What you put in it is basically gdb commands that you want executed when you start gdb. To create the file itself, just use any editor -- vi, nano, etc. -- and make sure it's in your home directory. Remember, "ls" won't show files like this by default, but "ls -a" will. Does that help, or are you asking something different?
@collinsedward3156
@collinsedward3156 7 жыл бұрын
MyGeekAdventures I want to set the disassembly flavor to intel permanently, Im using ubuntu on linux on windows (a linux shell for windows), now do I have to be root when I create that file?
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
you need to create .gdbinit in the home directory of the account from which you're going to run gdb. ~ always represents your home directory, so editing ~/.gdbinit will edit the right file. Putting the line set disassembly-flavor intel in ~/.gdbinit should do what you want. If you want this to be the default for *all* accounts, you'd need to edit the system-wide gdbinit file, but you need to do some work to find that or set it up.
@collinsedward3156
@collinsedward3156 7 жыл бұрын
when i create the file what do I set the name as? ~/.gdbinit or .gdbinit , sorry im asking basics, im completely new to this
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
~/.gdbinit means a file named ".gdbinit" inside the directory "~" (which means your home directory). If you just logged in, you'll be in your home directory, so editing .gdbinit should do the right thing; but editing ~/.gdbinit is explicitly saying in which directory you want the file. Alternatively, if your login name is (for example) nick, you could edit ~nick/.gdbinit ("~nick" means "the home directory of nick"). Or, on my system, this would be the directory /home/nick, so I could also edit /home/nick/.gdbinit There are usually several ways to do things in Unix!
@danielxu647
@danielxu647 9 жыл бұрын
thank you.
@DavidIrvinemetaquestions
@DavidIrvinemetaquestions 11 жыл бұрын
Great gdb 101
@austinmurphy9074
@austinmurphy9074 5 жыл бұрын
whats a sudo
@MyGeekAdventures
@MyGeekAdventures 5 жыл бұрын
"sudo" is the "SuperUser DO" command in Linux: it's used for executing commands as if you were logged in as (typically) root.
@yopachoman
@yopachoman 11 жыл бұрын
Thanks :)
@ivanderlich4432
@ivanderlich4432 6 жыл бұрын
Why didn't I learn this at college?
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
Ah well perhaps college prepared you to learn it now :) Glad it helped.
@pooriaheidary6204
@pooriaheidary6204 3 жыл бұрын
Horrible gdb goes easy. Thank you.
@MyGeekAdventures
@MyGeekAdventures 3 жыл бұрын
You're welcome! gdb can be a great tool once you know how to use it :)
@oussemahassini8207
@oussemahassini8207 6 жыл бұрын
wats this progrma
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
gdb? It's a debugger, generally standard in Linux systems. It allows you to single-step your code, examine variables/memory, and so on.
@xabelh.h2772
@xabelh.h2772 6 жыл бұрын
thanks
@MyGeekAdventures
@MyGeekAdventures 6 жыл бұрын
You're welcome!
@vertigo6982
@vertigo6982 7 жыл бұрын
scribed because... Gilfoyle.
@MyGeekAdventures
@MyGeekAdventures 7 жыл бұрын
LOL! Nice :)
@ruthlessadmin
@ruthlessadmin 5 жыл бұрын
KZbin needs to stop putting the toolbar OVER the videos. When I pause to read a command, it's hidden behind it >_
@MyGeekAdventures
@MyGeekAdventures 5 жыл бұрын
Ah yes I've noticed that myself on other videos. Kind of unfortunate. I could move the screen up a bit in the future...
@ruthlessadmin
@ruthlessadmin 5 жыл бұрын
@@MyGeekAdventures You shouldn't have to compensate for their bad design lol... anyway, VERY helpful video. I'm just getting my feet wet in C. Jumped off the deep end by porting some of my pure-Python modules to C, and predictably, things went tits up really fast. Some gdb knowledge saved the day!! Subbed/Liked
@imx27
@imx27 11 жыл бұрын
Blurred video, cant read the text...
@torke10
@torke10 6 жыл бұрын
es simbolo de pesos $
Using gprof for Code Profiling
11:51
MyGeekAdventures
Рет қаралды 461
GDB Tutorial
55:12
CS 246
Рет қаралды 75 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
Debugging with Core Dumps
9:16
Jacob Sorber
Рет қаралды 67 М.
x86 Assembly: Hello World!
14:33
John Hammond
Рет қаралды 1,4 МЛН
GDB Beginner Masterclass
23:31
Mike Shah
Рет қаралды 14 М.
Comparing C to machine language
10:02
Ben Eater
Рет қаралды 5 МЛН
How They Hack: Buffer Overflow & GDB Analysis - James Lyne
16:06
you need to stop using print debugging (do THIS instead)
7:07
Low Level
Рет қаралды 467 М.
Reverse Engineering w/GDB and Ghidra! | picoCTF 2022 #08 "Keygenme"
22:37
Debugging multithreaded code with GDB: thread names
12:31
C Dynamic Memory Debugging with Valgrind
17:51
Brian Fraser
Рет қаралды 136 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН