<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx</link><description>As I mentioned yesterday , one of the other developers in my group had hit a sticky problem, and he asked me for my opinion on what was going wrong. There were 3 pieces of information that I needed to use to diagnose the problem, I gave you two of them</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5125087</link><pubDate>Tue, 25 Sep 2007 20:18:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5125087</guid><dc:creator>Adam</dc:creator><description>&lt;p&gt;The ret 0Ch moves the stack pointer 12 bytes to clear up the args. The function only takes 8 bytes of parameters (the this pointer gets passed in ecx). I believe that means there's a parameter mismatch.&lt;/p&gt;
&lt;p&gt;As for how it compiled I can only assume that there's two versions of the IPsychicInterface - one that is being compiled with and another that is being linked with.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5125234</link><pubDate>Tue, 25 Sep 2007 20:28:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5125234</guid><dc:creator>Skywing</dc:creator><description>&lt;p&gt;If it's within the same program, I would say that two source files had different compiler settings. &amp;nbsp;The compiler wouldn't catch the call at compile time if it's a virtual function call as that doesn't require a linker lookup against the decorated symbol name (which would be wrong if the calling convention was mismatched across two files).&lt;/p&gt;
&lt;p&gt;Another possibility is that one source file was compiled with different padding or class layout options than another source file.&lt;/p&gt;
&lt;p&gt;Being in the same problem, it would seem to be that it's a violation of the one definition rule...&lt;/p&gt;
</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5125271</link><pubDate>Tue, 25 Sep 2007 20:30:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5125271</guid><dc:creator>Skywing</dc:creator><description>&lt;p&gt;Wow, that last sentence did not come out right at all :)&lt;/p&gt;
&lt;p&gt;&amp;quot;Being in the same program, it would seem to me that it's a violation of the one definition rule...&amp;quot;&lt;/p&gt;
</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5125779</link><pubDate>Tue, 25 Sep 2007 21:00:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5125779</guid><dc:creator>Stuart Ballard</dc:creator><description>&lt;p&gt;Larry, have you answered the question of whether the interface, the class implementing the interface, and the application using the interface were all compiled together yet?&lt;/p&gt;
&lt;p&gt;I can't say I actually understand the problem (and the assembly snippet made it more opaque rather than less to me) but it seems like if the interface were compiled twice, once with one calling convention and once with the other, and then the application and the implementing class were compiled against those different copies, it might cause this kind of problem?&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5125925</link><pubDate>Tue, 25 Sep 2007 21:07:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5125925</guid><dc:creator>LarryOsterman</dc:creator><description>&lt;p&gt;Darn it all, Skywing. &amp;nbsp;I was planning on being really geeky and mentioning the ODR and you went ahead and spoiled it for me :).&lt;/p&gt;
&lt;p&gt;Nice job.&lt;/p&gt;
</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5126157</link><pubDate>Tue, 25 Sep 2007 21:20:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5126157</guid><dc:creator>Tim Smith</dc:creator><description>&lt;p&gt;LOL...&lt;/p&gt;
&lt;p&gt;I was looking for really technically obscure reasons and missed the obvious one of someone doing something REALLLLLY dumb. &amp;nbsp;I hope it really wasn't the case of the interface being cut/copied/pasted to two different locations.&lt;/p&gt;
&lt;p&gt;In a big and complex code base, I could see someone having this problem similar to the issues you see when two modules use different settings for such things as WINVER.&lt;/p&gt;
&lt;p&gt;Two definitions, different vtable ordering, the wrong routine getting called.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5126594</link><pubDate>Tue, 25 Sep 2007 21:43:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5126594</guid><dc:creator>barrybo</dc:creator><description>&lt;p&gt;&amp;quot;thiscall&amp;quot; strikes again!&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5126952</link><pubDate>Tue, 25 Sep 2007 22:02:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5126952</guid><dc:creator>Tim Smith</dc:creator><description>&lt;p&gt;Barry: How is this an issue with thiscall?&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5128832</link><pubDate>Tue, 25 Sep 2007 23:25:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5128832</guid><dc:creator>Justin Rudd</dc:creator><description>&lt;p&gt;Since the type of parameter is _TCHAR, my guess is that one or the other compilation units was compiled with _UNICODE defined. &amp;nbsp;The compilation unit that had it defined saw _TCHAR == wchar_t and the one that didn't saw _TCHAR == char.&lt;/p&gt;
&lt;p&gt;Originally I didn't see how that would cause a stack problem because it is an array of pointers which is still 4 bytes no matter wchar_t or char.&lt;/p&gt;
&lt;p&gt;The only thing I can think of is if DoSomeOperation used the ATL character conversion functions, those use stack space. &amp;nbsp;And those would think that the pointer coming in contained the wrong character set and that might stomp on the stack a bit.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5130238</link><pubDate>Wed, 26 Sep 2007 01:15:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5130238</guid><dc:creator>anon</dc:creator><description>&lt;p&gt;I am not quite sure if this is what skywing was getting at, but I was trying to see if it was possible to define an overload of the DoSomeOperation method that would take 3 or more parameters, with the 3rd taking a default value. In which case, the compiler might not complain about the call in the code above (viz default value assigned), but such an overload does not satisfy the implementation for the virtual DoSomeOperation method (you're left with an abstract class)... &lt;/p&gt;
&lt;p&gt;So I am not sure. Sorry for rambling.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5130646</link><pubDate>Wed, 26 Sep 2007 01:56:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5130646</guid><dc:creator>B.Y.</dc:creator><description>&lt;p&gt;From the disassembly, it's obvious DoSomeOperation() is using a calling convention where the callee cleans up the stack. &lt;/p&gt;
&lt;p&gt;Let assume _tmain is using the default C calling convention, where the caller cleans up the stack. The fact that the program run means it linked OK, so that means GetPsychicInterface() most likely got the interface from a DLL or something, where the interface was compiled and linked using a non-C calling convention.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5131638</link><pubDate>Wed, 26 Sep 2007 03:03:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5131638</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Was the IPsychicInterface object implemented in C (rather than C++)? This is possible (although a little unorthodox these days). If so, then the implementation of DoSomeOperation() is likely using the wrong calling convention.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5131777</link><pubDate>Wed, 26 Sep 2007 03:15:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5131777</guid><dc:creator>LarryOsterman</dc:creator><description>&lt;p&gt;Charlie, nope. &amp;nbsp;Skywing nailed it the first post: it was a violation of the one definition rule.&lt;/p&gt;
</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5132021</link><pubDate>Wed, 26 Sep 2007 03:34:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5132021</guid><dc:creator>JCAB</dc:creator><description>&lt;p&gt;Nitpick:&lt;/p&gt;
&lt;p&gt;&amp;quot;the last bit of assembly language&amp;quot; indicates that there will be a stack imbalance _after_ returning from DoSomeOperation. That wouldn't show as a trashed ESI upon returning from DoSomeOperation.&lt;/p&gt;
&lt;p&gt;There must be some other imbalance (ODR violation or otherwise) inside of DoSomeOperation.&lt;/p&gt;
&lt;p&gt;&amp;quot;the last bit of assembly language&amp;quot; does indicate that there is ODR violation in the program, so it's likely that the other imbalance will also be caused by ODR in some other function called from inside of DoSomeOperation, but not certain.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5147769</link><pubDate>Wed, 26 Sep 2007 20:06:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5147769</guid><dc:creator>Amit</dc:creator><description>&lt;p&gt;I think this is a mismatch between stdcall and thiscall.&lt;/p&gt;
&lt;p&gt;The function is implemented as stdcall and the caller is assuming the thiscall. &lt;/p&gt;
&lt;p&gt;If for the for implementer the calling convention is defined (in some header file) as stdcall and for the user it is defined as thiscall (in a different header file or as a compiler setting) it will keep the compiler happy.&lt;/p&gt;</description></item><item><title>re: What's wrong with this code, Part 21 - A psychic debugging example: The missing piece</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5147836</link><pubDate>Wed, 26 Sep 2007 20:11:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5147836</guid><dc:creator>LarryOsterman</dc:creator><description>&lt;p&gt;A mismatch between stdcall and fastcall would have presented differently - the stack would be unbalanced low, not high, and the function would likely have crashed because it's parameters weren't enregistered as expected.&lt;/p&gt;
</description></item><item><title>What's wrong with this code, part 21 - A Psychic Debugging Example - The answers.</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5151069</link><pubDate>Wed, 26 Sep 2007 23:17:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5151069</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description>&lt;p&gt;So for the past couple of posts , I've been walking through a psychic debugging experience I had over&lt;/p&gt;
</description></item><item><title>What's wrong with this code, part 21 - A Psychic Debugging Example - The answers.</title><link>http://blogs.msdn.com/larryosterman/archive/2007/09/25/what-s-wrong-with-this-code-part-21-a-psychic-debugging-example-the-missing-piece.aspx#5151656</link><pubDate>Wed, 26 Sep 2007 23:27:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5151656</guid><dc:creator>Noticias externas</dc:creator><description>&lt;p&gt;So for the past couple of posts , I&amp;amp;#39;ve been walking through a psychic debugging experience I had&lt;/p&gt;
</description></item></channel></rss>