Raised This Month: $ Target: $400
 0% 

Debugging SIGSEGV with GDB?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-11-2011 , 11:54   Debugging SIGSEGV with GDB?
Reply With Quote #1

OK, I didn't really want to do this, but...

Is it possible to attach a watch on a class/object's property?

I'm writing a SourceMod Extension for vote handling using TF2 votes, based quite heavily on the SourceMod vote system. The problem I'm having is that one of my global classes is throwing a SIGSEGV after I copy one of its pointer properties to a new pointer and try to call a method on it.

Specifically, this happens if no one votes (I haven't tested the voting yet to make sure votes are tallying correctly).

Note: The attached code needs a lot of cleanup yet, with the wholesale slashing of some unnecessary blocks (like anything dealing with the watch list).

The relevant parts of the code are (in the order they're called):
extension.cpp line 50, where s_VoteHandler is created just once (so it's a global).

nativse.cpp line 299, where a pointer to a new CBuiltinVoteHandler is created, or an old, no longer used pointer is retrieved from the pool during vote creation. During testing, this was the first vote created. This is during the CreateBuiltinVote native.

natives.cpp line 314, where the vote is started from the DisplayBuiltinVote native.

BuiltinVoteHandler.cpp line 378, where the CBuiltinVoteHandler pointer from earlier is copied to BulltinVoteHandler's m_pHandler pointer.

BuiltinVoteHandler.cpp line 380, where we send a command to the handler. We know m_pHandler is valid at this point.

BuiltinVoteHandler.cpp line 396, where the timer starts.

BuiltinVoteHandler.cpp line 723, where the timer stops.

BuiltinVoteHandler.cpp line 733, where EndVoting is called after the timer stops

BuiltinVoteHandler.cpp line 484, where the m_pHandler pointer is copied to a local variable

BuiltinVoteHandler.cpp line 614, where m_pHandler is set to NULL.

BuiltinVoteHandler.cpp line 486, where the SIGSEGV for the local handler happens during the EndVoting method.

Note: I haven't yet tested this on Windows. Also, you need to compile it for Orange Box Valve. The msvc9 and msvc10 projects should both work, as should the Makefile.

Edit: I forgot to mention, no natives are called after DisplayBuiltinVote before the crash.

Edit 2: If it's not that easy, I suppose I could set up a local dedicated server to test it using Visual Studio.
Attached Files
File Type: zip builtinvotes_src.zip (59.9 KB, 115 views)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-11-2011 at 14:33.
Powerlord is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 10-11-2011 , 14:34   Re: Debugging SIGSEGV with GDB?
Reply With Quote #2

Compile with debug info and start srcds in gdb (or attach after it's started). When it segfaults, you can do, for example, 'p/x handler' at the prompt to look at the address in the variable (assuming handler is in scope where it crashes). If it's crashing on the call, then the problem is likely just that the pointer is bad, whether it's null or just wrong.

You can add watches for read/writes to memory locations/variables with the rwatch and watch commands.
Fyren is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-12-2011 , 09:51   Re: Debugging SIGSEGV with GDB?
Reply With Quote #3

I did some debugging on a Windows server yesterday. I think I discovered why the error is happening. It looks like the EndVoting() method is being called twice. I found this out while doing Step Into in visual studio, then when I got near the end of the method (after it went through all the calls correctly) I hit the Continue button... when it promptly crashed at one of the lines I'd already gone past.

This should not be happening, so now I need to figure out why it's doing that.

Edit: I think I found the root cause. The root cause was two things together that were causing the error. The first was the wrong value for m_Clients being set (or not being set at all), which caused EndVoting() to be called immediately when the vote started. The second was BuiltinVoteHandler line 396 not saving the timer to the m_displayTimer variable like it was supposed to. This prevented the timer from being canceled when EndVoting() was called the first time, but the other variables were cleared as expected, therefore they didn't have a value the second time EndVoting was called.

I have to redo the vote display code anyway, so I'll fix m_Clients when I do.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-12-2011 at 10:05.
Powerlord is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode