roomforthetuna posted:This would be a good time to learn some debugging techniques, I'd say. This is something I've been meaning to do for a while. Where's a good place to start?
|
|
# ? May 2, 2015 19:00 |
|
|
# ? Jun 8, 2024 08:56 |
|
VikingofRock posted:This is something I've been meaning to do for a while. Where's a good place to start? gdb is the Linux command-line debugger, it's not much fun but it just about works. It's often easier to use the old-school option than it is to use gdb. Visual Studio makes it super easy, you click next to the code you want to debug and a red dot appears, when the code gets there it stops, then there are keystrokes to move around in code, all of which are explained in the Debug menu, and it automatically shows the values that are in the nearby variables you're likely to care about. There's a Linux IDE that does that too but I don't know what it is (and there's also Visual Studio for Linux now). Or you can do it old-school, which tends to be necessary for multi-threaded things or client-server things, which is to just put lines in your code that write the stuff you care about at the times you care about it to stdout or stderr. Or if you just want to see what the code path is, I often just do something like code:
I've never seen anything that tries to *teach* debugging techniques. It's a really weird gap in CS curricula, interview tests, etc. roomforthetuna fucked around with this message at 20:07 on May 2, 2015 |
# ? May 2, 2015 20:03 |
|
The Linux IDE you're thinking about is likely Netbeans, but its debugging isn't nearly as nice as Visual Studio, especially for things like containers; vectors are a huge pain in the rear end to debug in Netbeans.
|
# ? May 2, 2015 20:13 |
CLion's debugging (which uses gdb) works almost as well as Visual Studio's. You can make break points, investigate all symbols in scope and you can even hover your mouse over symbols in your code to see their values when the program has stopped at a break point. (it also adds comments in your code showing the current break point value of symbols at their declarations.) I'm not sure what your options to get CLion is at the moment unless you're a student, but at the very least there's a 30 day trial period. I'm pretty sure you can get it for free for non-commercial applications though. This is debugging with CLion in action: Honestly I'm liking it more the more I work with it. It's super easy to set up too, as long as you make sure your gdb version corresponds to your gcc version (this should be automatic if you just use your standard repos versions.) One thing I'm missing is some automatation for investigating STL containers like vectors, since browsing through iterators to find the actual values can be a pain in the rear end. E: You can actually get full-blown VS + MSVC for Linux now? I thought I heard something like that, but all I could find was Visual Studio Code, which seemed like it was geared more towards net developers. Joda fucked around with this message at 20:56 on May 2, 2015 |
|
# ? May 2, 2015 20:29 |
|
roomforthetuna posted:I've never seen anything that tries to *teach* debugging techniques. It's a really weird gap in CS curricula, interview tests, etc.
|
# ? May 2, 2015 20:38 |
|
Star War Sex Parrot posted:Are you talking an entire course devoted to debugging techniques? I've encountered several programming courses throughout my degree that taught different methods depending on the language and IDE: break points, copious printing to the console, stepping into/through code, Google Test for unit testing, dynamic analysis with Valgrind and AddressSanitizer, as well as entire courses devoted to software engineering best practices (especially testing). I wouldn't say there was a huge gap in my CS curricula. My suspicion is that it depends on the school and the degree. I didn't mean an entire course - unless you get into unit testing frameworks and stuff there isn't really that much you need to learn. But every "programming 101" should have at least a small mention of how you go about figuring out why stuff doesn't work (other than the ridiculous "dry run in your head" model from the days of punch cards), and a lot of them don't. I haven't seen it in a book or online tutorial either, other than "how to use gdb" tutorials which are a layer too late to be helpful to beginner programmers who don't know that there is such a thing or when to use it.
|
# ? May 2, 2015 20:55 |
|
roomforthetuna posted:I'm sure it depends on the place. It seems like yours is the exceptional case, because internet questions about why poo poo's not working are clearly coming from people who haven't been taught any way to debug, but I suppose that might just be selection bias, maybe 95% of places teach that stuff and you just don't see any questions from those people because they can all solve their own "why doesn't this work" problems.
|
# ? May 2, 2015 21:22 |
|
roomforthetuna posted:This would be a good time to learn some debugging techniques, I'd say. That being said, a debugging class would be a lot of fun. America Inc. fucked around with this message at 22:04 on May 2, 2015 |
# ? May 2, 2015 21:58 |
roomforthetuna posted:What's your development environment? Mostly I just code in vim, and use the "print strings in places" method of debugging. I was wondering if there were any good gdb/valgrind learning resources out there.
|
|
# ? May 2, 2015 23:31 |
|
roomforthetuna posted:gdb is the Linux command-line debugger, it's not much fun but it just about works. It's often easier to use the old-school option than it is to use gdb. There's a GUI shell for gdb called "ddd" which is a bit easier to use. http://www.gnu.org/software/ddd/
|
# ? May 3, 2015 12:59 |
|
Zopotantor posted:There's a GUI shell for gdb called "ddd" which is a bit easier to use. What's remarkable about ddd is how well it has stood the test of time, given it operates by parsing the output of gdb, rather than having using a proper API. This may be because the API did not exist when it was first written and it works well enough (barring the occasional breakage when the output of gdb changes format) that nobody has invested time in fixing it.
|
# ? May 3, 2015 13:11 |
|
VikingofRock posted:Mostly I just code in vim, and use the "print strings in places" method of debugging. I was wondering if there were any good gdb/valgrind learning resources out there. Valgrind is pretty straight-forward. Compile your program with debug symbols (-g) and then just run valgrind my_program my_programs_args The trick is learning how to interpret the output; just like compiler error messages, start at the top and fix one problem at a time. Once you get comfortable with valgrind, you can start looking at all of the extra options and tools beyond memcheck (which verify thread synchronization and can profile your program, among other things.) I really don't think you need anything beyond the valgrind man page to get going. gdb is a little trickier--it can do a lot and more advanced functionality is not always obvious. Since you're a vim user, I'd look towards one of the projects that integrates gdb with the editor. I use emacs, which has good gdb support built in, and I've been told vim can be configured to work similarly. That might help you do basic things like set breakpoints, step through code, and examine variables using an interface you already know. More recent versions of gdb support nifty things like reverse debugging, which allows you to rewind the execution of your program from a given point. There's also an interface between valgrind and gdb, which I've never used, but I'm assuming you didn't mean that.
|
# ? May 3, 2015 16:38 |
|
ExcessBLarg! posted:Why? In game development it's not uncommon to design data structures this way. It's an optimization for loading times and enables some neat features like saving and loading game state without requiring any complex serialization or fixup.
|
# ? May 3, 2015 19:16 |
|
Paniolo posted:In game development it's not uncommon to design data structures this way.
|
# ? May 4, 2015 00:33 |
|
ExcessBLarg! posted:I appreciate the convenience of "blatting struct to file" as a means of data serialization, albeit one with serious limitations and portability concerns. However I think it's a bit dubious, without motivation, to design a primary data structure around being convenient to serialize. There's better general approaches, especially in C++. Sure, you shouldn't be reinventing the wheel in a professional environment but sometimes having trivial serialization is worth the associated headaches.
|
# ? May 4, 2015 02:06 |
|
Clearly you should be serializing to JSON in order to get closer to the bare metal.
|
# ? May 4, 2015 02:10 |
|
Why doesn't C++ support identifiers as template parameters? Ignoring the issue of syntax, are there any technical reasons that hasn't ever been implemented? To explain why I think this would be useful, I would like to be able to write a template function that returns the value of member of an object or some default value if the object doesn't have such member. Currently this is possible if you create one function for each member name you want to check, but it would be cleaner to have just one function that the member name is passed as a template parameter.
|
# ? May 4, 2015 08:55 |
You should be able to make a functor to do that. Not sure if the syntax is valid, but: C++ code:
|
|
# ? May 4, 2015 09:50 |
|
C++ code:
There is surely an easier way to do this with stuff like std::enable_if, but I don't know. Deus Rex fucked around with this message at 11:02 on May 4, 2015 |
# ? May 4, 2015 10:59 |
|
quote:e: I'm not sure what the rule on double posting is so I'll just edit this post instead. I finished my HashTable assignment but I'm having trouble with a few of the entries and I'm not quite sure why the other ~40 or so entries work just fine. I'd also like some pointers on how I could optimize / clean my code (StrTab.cpp) up if anyone has any. Here's a gist of my assignment so I don't clutter the thread anymore. Hate to quote myself but anyone have any advice? Due at 5 today just looking for general advice to clean my code up.
|
# ? May 4, 2015 19:11 |
Diametunim posted:Hate to quote myself but anyone have any advice? Due at 5 today just looking for general advice to clean my code up. I was writing a comment on how your memory management of the StrTab::stNode objects is really messy with double pointers, but then I noticed you are doing the buckets a different way than I thought. The basic structure I've learned for hash tables is to not do straight linked lists with "free objects" hanging on, but instead keep every item in the same single table, and then just have indices to items in the table hanging around. The kind of array of pointers you're doing is sort of messy, memory-wise. For your bug with items not working, notice that you have 13 items that don't work. Your bucket count is 13. Most likely, you're either skipping the first or the last item in each bucket. Also, double posting is fine when you're actually writing something new you want attention on, and it's been a while since your last post. Based on the edit time given, it was almost two days between your original post and the edit. Of course nobody's going to notice that change. nielsm fucked around with this message at 19:28 on May 4, 2015 |
|
# ? May 4, 2015 19:24 |
|
Idk if I pasted this in wrong but you're not initializing the links in your linked list to NULL so I get access violations.code:
Your linked list strategy is to add a dummy link at the beginning which is incorrect and it doesn't examine the last item. code:
Sex Bumbo fucked around with this message at 20:11 on May 4, 2015 |
# ? May 4, 2015 20:00 |
|
nielsm posted:I was writing a comment on how your memory management of the StrTab::stNode objects is really messy with double pointers, but then I noticed you are doing the buckets a different way than I thought. Sex Bumbo posted:Idk if I pasted this in wrong but you're not initializing the links in your linked list to NULL so I get access violations. Thank you both for the help, got everything sorted out!
|
# ? May 4, 2015 20:38 |
|
I want the poo poo out of this for Visual Studio. How many limbs is this going to cost me???
|
# ? May 5, 2015 13:34 |
|
MrBadidea posted:I want the poo poo out of this for Visual Studio. How many limbs is this going to cost me??? Do you mean the mouse over tooltip variable values? It does that already, doesn't work so well for stl types though.
|
# ? May 5, 2015 13:47 |
|
StorrowS posted:Do you mean the mouse over tooltip variable values? It does that already, doesn't work so well for stl types though. No, the inline variable view; the not-quite-a-comment poo poo appended to a bunch of the lines in that screenshot. It makes way more sense to me than the watch window, and it kinda sits better with how I headspace code I'm working on.
|
# ? May 5, 2015 15:50 |
|
MrBadidea posted:No, the inline variable view; the not-quite-a-comment poo poo appended to a bunch of the lines in that screenshot. It makes way more sense to me than the watch window, and it kinda sits better with how I headspace code I'm working on. CLion is available for windows now, and I imagine if it allows it ReSharper C++ will have it at some point.
|
# ? May 5, 2015 16:12 |
|
MrBadidea posted:No, the inline variable view; the not-quite-a-comment poo poo appended to a bunch of the lines in that screenshot. It makes way more sense to me than the watch window, and it kinda sits better with how I headspace code I'm working on. I see what you mean. Yes that would be very handy.
|
# ? May 5, 2015 16:15 |
|
MrBadidea posted:I want the poo poo out of this for Visual Studio. How many limbs is this going to cost me??? When you inspect a variable you can click the little pin icon for a similar effect.
|
# ? May 5, 2015 17:03 |
MrBadidea posted:I want the poo poo out of this for Visual Studio. How many limbs is this going to cost me??? An individual license is €99 (I imagine it's the same in USD.) Free for educational/open source purposes. To my knowledge, though, the Windows version requires GCC (through MinGW or Cygwin) and won't work with MSVC.
|
|
# ? May 5, 2015 17:07 |
|
I'd like some help on how to do something, I'm using Qt if that makes a difference. I have an SQL record object (containing all the fields of a specific table) that I pass to a class that creates all the labels/edits needed to fill the values and I'd like for it to update the sql record with the values entered by the user and return it back to me. I can create all the fields with their name and types without problem but how can I do it easily so that when the user modify the edit values it automatically updates the content of my SQL record object so that I can return it updated at the end?
|
# ? May 10, 2015 13:57 |
|
I have a LLDB-related question. I've solved the issue, but I'm curious as to why it happens and maybe knowing about this may help someone else. I've got a program where I send it an SQL query to run in it's command line arguments. I've been terminating the queries with semicolons when I pass it to the program, but I have to do \; since otherwise bash interprets it as 2 complete commands. code:
code:
code:
|
# ? May 10, 2015 17:55 |
|
I don't know the details of what lldb is doing (it isn't passing the command to bash fwiw, it has to exec the program directly for debugging), but bash shouldn't be interpreting the semicolon in the single quotes in the first place.
|
# ? May 10, 2015 18:02 |
|
Eeyo posted:LLDB seems to have lost 2 of my arguments somehow. This works fine when I escape the semicolon when I set the arguments. What's happening here? Why does LLDB not like the semicolon at all? Does it pass the arguments through bash, or does it do some of its own interpreting so that the semicolon breaks it? It does its own interpreting and apparently doesn't honor string literals correctly.
|
# ? May 10, 2015 20:16 |
I did a cool C++ thing: FizzBuzz in Template Meta ProgrammingC++ code:
VikingofRock fucked around with this message at 07:21 on May 12, 2015 |
|
# ? May 12, 2015 06:54 |
|
I have an assignment in which I am to use RTTI to first output a set of objects that share the same superclass to a file, then read that data back in and determine what type of object they are (I don't actually know how feasible this even is, the prof said he has never done it before). However just trying to output object data to the console (it would be an easy transition to a write this to a file afterward) I am having difficulty getting any of the methods in the typeinfo class to do anything useful for me. I have a class Vehicle which has subclasses TruckVehicle, MotorcycleVehicle, and TrailerVehicle which has a subclass of TravelTrailerVehicle itself. I created an array of vehicles as below: array<Vehicle*,5> v; v[0] = new Vehicle(params) v[1] = new TruckVehicle (params) v[2] = new MotorcycleVehicle(params) v[3] = new TrailerVehicle(params) v[4] = new TravelTrailerVehicle (params) Now what I would like to do is iterate through this array and use RTTI to determine the data type, then downcast to the appropriate subclass so that the correct subclass display method is called (I have overwritten the cout operator in each subclass). Something like this is what I was hoping would work but it's too simple. for(int x=0;x <(int)v.size;x++) { Vehicle temp = *v[x]; cout<<dynamic_cast<typeid(temp)>(temp); } Anyone have any ideas on this? Gotta love a prof who assigns something he isn't even sure if it's possible to do.
|
# ? May 12, 2015 19:18 |
C++ is not dynamic in that way. There isn't a good way to create objects of an "unknown type", you need to know about all types that could be created in one way or another. What you might be able to do, which will probably only work inside a single compiler + standard library version, is have each class be registered in some way. The registration must include the std::type_info for the class (which importantly has the name member) and the sizeof the actual class instance. You could then dump the name from the type_info, the sizeof the instance, and a plain dump of the actual instance memory, to a file. To read it back you would read the name and the size, search for the name in the new process' registration table, and check that the size matches. Then allocate a new chunk of memory of the size and read the dumped data into that. You may then need to fix up the vtable pointer in the object to bring it back to life, and then you can cast the block of memory to a pointer of the base type and play with it. That is if you really must use RTTI. What is probably more common for serialization is building on the factory pattern and let each class have a member function that dumps its data into a stream, then have registered another function/something that rebuilds an instance of the object from a stream.
|
|
# ? May 12, 2015 19:53 |
|
How much time would I waste learning the overhead for a minimal C++ GUI to make the desktop equivalent of like Photoswipe, I think it's called? (Shows photos in a slideshow, asks you keep or delete.) I'm sure it already exists, though I can't find it, and I'm sure I could knock it out in Python in a few hours, but this sounded like a simple project to step from a cursory tutorial knowledge of C++ to "an actual thing that works".
|
# ? May 12, 2015 21:36 |
|
That depends on what you use... Windows has a lot of boilerplate that you have to run through, and you might end up using GDI/GDI+ for graphics. A long time ago, I worked with GDI and tried to explain it a bit in a little tutorial, if you're interested. It is full of terrible advice and such, but the code is pretty solid.
|
# ? May 13, 2015 00:18 |
|
|
# ? Jun 8, 2024 08:56 |
|
Evil_Greven posted:That depends on what you use... Windows has a lot of boilerplate that you have to run through, and you might end up using GDI/GDI+ for graphics.
|
# ? May 13, 2015 01:09 |