I declare two variables and call a function. The second to last statement
seems fishy to me. My other non-static function calls to other methods in
the same class do not have "this" line. Furthermore, after executing this
line, the addresses of my local variables change.
Is this normal?
Thanks,
Chris
===
int Ni;
double dt;
GetTrackDropPar ms(Track, dt, Ni);
01610981 lea ecx,[Ni]
01610984 push ecx
01610985 lea edx,[dt]
01610988 push edx
01610989 mov eax,dword ptr [Track]
0161098C push eax
0161098D mov ecx,dword ptr [this]
01610990 call CtTracker::GetT rackDropParms (0BC1830h) 12 1604
I take back what I said about not seeing "this" line in other non-static
calls to methods in the same class.
Nevertheless, when "this" assembly instruction is executed, the addresses of
local variables change. Why is that happening?
Chris
"Chris Stankevitz" <ch******@stank evitz.nospample ase.com> wrote in message
news:ux******** ******@TK2MSFTN GP14.phx.gbl... I declare two variables and call a function. The second to last statement seems fishy to me. My other non-static function calls to other methods in the same class do not have "this" line. Furthermore, after executing this line, the addresses of my local variables change.
Is this normal?
Thanks,
Chris
===
int Ni; double dt; GetTrackDropPar ms(Track, dt, Ni); 01610981 lea ecx,[Ni] 01610984 push ecx 01610985 lea edx,[dt] 01610988 push edx 01610989 mov eax,dword ptr [Track] 0161098C push eax 0161098D mov ecx,dword ptr [this] 01610990 call CtTracker::GetT rackDropParms (0BC1830h)
"Chris Stankevitz" <ch******@stank evitz.nospample ase.com> wrote in message
news:Oo******** ******@TK2MSFTN GP09.phx.gbl... Nevertheless, when "this" assembly instruction is executed, the addresses of local variables change. Why is that happening?
Well, if it is a real problem it could be stack corruption. Less likely is
debugger weirdness. Can you pare the problem down to some small, compilable
snippet that you can post here?
Regards,
Will
"William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. Well, if it is a real problem it could be stack corruption. Less likely is debugger weirdness. Can you pare the problem down to some small, compilable snippet that you can post here?
Regards, Will
Thanks for the reply Will,
The application is a large (1 million lines) simulation. I'm unable to
shrink it down.
Can someone recommend ways to go about debugging "stack corruption"? I have
lots of time, so I'd be happy with even tedious ways. I just want to figure
out what is going on.
Thanks,
Chris
Chris Stankevitz wrote: "William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. .. Well, if it is a real problem it could be stack corruption. Less likely is debugger weirdness. Can you pare the problem down to some small, compilable snippet that you can post here?
Regards, Will
Thanks for the reply Will,
The application is a large (1 million lines) simulation. I'm unable to shrink it down.
Can someone recommend ways to go about debugging "stack corruption"? I have lots of time, so I'd be happy with even tedious ways. I just want to figure out what is going on.
Stack corruption is usually the result of one of the following:
- Over-indexing a local varaible (array). Compiling with /RTCsu (VC7+)
should catch this kind of error.
- Calling a function through a function pointer of the wrong type (e.g.
calling a __stdcall function through a __cdecl pointer will remove the
parameters from teh stack twice).
I have seen cases in the past (VC6) where the debugger does not show member
variables correctly when executing in a virtual member function that was
originally declared in a non-leftmost base class (i.e. in a situation where
there's a 'this-pointer adjustment' in effect - the debugger is apparently
unaware of the adjustment).
What version of the compiler are you using? Can you describe the taxonmy
and structure of the CtTracker class and the class where the call appears
(if I follow what you've posted correctly, you're calling one non-static
member function from another)?
Make sure you're not seeing debugger wierdness - it does happen. Write some
local variables out to the console or to OutputDebugStri ng before and after
the call in question and verify that the values do appear to change.
-cd
"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:uy******** ******@TK2MSFTN GP14.phx.gbl... What version of the compiler are you using? Can you describe the taxonmy and structure of the CtTracker class and the class where the call appears (if I follow what you've posted correctly, you're calling one non-static member function from another)?
Thanks for your help. It's not debugger weirdness.
Version: VC .net 2003 7.1
Microsoft Visual C++ .NET 69462-270-0000007-18536
CtTracker inherits from one other class. No multiple inheritance, so there
isn't "multiple inheritance" kind of 'this-pointer adjustment'. Neither
function is virtual so there is no "non-leftmost" issue, although to be
honest I don't understand that. Neither function is static.
I suspect I'm stomping on memory somewhere in the "past". I ran the case
through Rational Purify hoping to detect the stomping, but came up empty. I
will try compiler option /RTCsu with which I am presently unfamiliar.
Let me ask this question:How do I determine if stack corruption is taking
place?
Possible answer:
Watch register ESP. If it changes while stepping through a function, you've
got stack corruption.
Possible follow up question:
Should changes in ESP be visible in the "disassembl y" view?
etc. etc.
Another possible question:
I understand local variables are offsets to the stack frame pointer. How
can I see these offset values? I would like to verify that they are not
changing while the function is executing. Disassembly does not show the
offset values (I think).
This is the "systematic " way I would like to go about solving this problem
(I think).
PS: When my local variable addresses change, ESP does not change.
Thanks again for your help!
Chris
Carl Daniel [VC++ MVP] wrote: Stack corruption is usually the result of one of the following:
- Over-indexing a local varaible (array). Compiling with /RTCsu (VC7+) should catch this kind of error. - Calling a function through a function pointer of the wrong type (e.g. calling a __stdcall function through a __cdecl pointer will remove the parameters from teh stack twice).
I'd like to add one more case when two compiled modules are not byte
compatible. For example:
- Borland treats enums as single bytes by default, while other compilers
treat them as ints (4 bytes).
- Different structure packing alignment was used when compiling a
particular module (the default pragma pack was different for a DLL).
- Some class members in the header file may have been inside an #ifdef
(such as #ifdef _DEBUG), which was defined while compiling your DLL, but
not when compiling your main app.
I've experienced all 3 of the above problems, all of which can (usually)
be detected by comparing sizeof(T)'s. Example:
// In DLL
class MyClass
{
public:
static int GetMySize() const;
}
// to .cpp (make sure it's not inlined)
int MyClass::GetMyS ize() const
{
return sizeof(MyClass) ;
}
// In EXE
assert(MyClass: :GetMySize() == sizeof(MyClass) );
Your stack can be corrupted when you pass a local variable to a function
by pointer or by reference, and there is a sizeof mismatch.
Tom
Chris Stankevitz wrote: "Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam> wrote in message news:uy******** ******@TK2MSFTN GP14.phx.gbl... What version of the compiler are you using? Can you describe the taxonmy and structure of the CtTracker class and the class where the call appears (if I follow what you've posted correctly, you're calling one non-static member function from another)?
Thanks for your help. It's not debugger weirdness.
Version: VC .net 2003 7.1 Microsoft Visual C++ .NET 69462-270-0000007-18536
CtTracker inherits from one other class. No multiple inheritance, so there isn't "multiple inheritance" kind of 'this-pointer adjustment'. Neither function is virtual so there is no "non-leftmost" issue, although to be honest I don't understand that. Neither function is static.
Non-leftmost refers to the order of inheritance in a multiple inheritance
case. No MI - no non-leftmost bases.
I suspect I'm stomping on memory somewhere in the "past". I ran the case through Rational Purify hoping to detect the stomping, but came up empty. I will try compiler option /RTCsu with which I am presently unfamiliar. Let me ask this question:How do I determine if stack corruption is taking place?
It's hard. Possible answer: Watch register ESP. If it changes while stepping through a function, you've got stack corruption.
ESP or EBP or the contents of the stack itself could be modified. Normally,
it's the contents of the stack that get modified, then on returning from a
function, an incorrect value of EBP gets picked up off the corrupted stack,
followed shortly by fireworks as your program blows holes in itself. Possible follow up question: Should changes in ESP be visible in the "disassembl y" view?
Yes, it's visible in the Registers window along with all the others.
Debug|Windows|R egisters from the menu or Ctrl-Alt-G from the keyboard if the
reigsters window isn't visible. etc. etc.
Another possible question: I understand local variables are offsets to the stack frame pointer. How can I see these offset values? I would like to verify that they are not changing while the function is executing. Disassembly does not show the offset values (I think).
The offsets are hard-wired into the code by the compiler, and may change
from point to point depending on calling patterns and optimization level.
Normally, in debug builds, all locals are accessed using offsets from EBP
and those offsets are fixed. However, in an optimized build, the compiler
may choose to not use EBP and reference variables directly off ESP. In this
case, the offset to a variable might be different at two points in a single
function if the compiler has pushed parameters for a function call, or
spilled temporary values to the stack. The compiler keeps track of
everything it's put on the stack at each point and will generate the correct
offset(s), but it can make the disassembly a bit hard(er) to follow. This is the "systematic " way I would like to go about solving this problem (I think).
PS: When my local variable addresses change, ESP does not change.
How do you conlucde that the address changes?
Are you debugging an optimized build, or a debug build?
-cd
"Chris Stankevitz" <ch******@stank evitz.nospample ase.com> wrote in message
news:ua******** *******@TK2MSFT NGP10.phx.gbl.. . Can someone recommend ways to go about debugging "stack corruption"? I have lots of time, so I'd be happy with even tedious ways. I just want to figure out what is going on.
Well, if you have _lots_ of time, and if the local variables are smallish,
you might want to put a few of them in the watch window. Use addresses
rather than names because names go out of scope. Then put breakpoints at
entry to each of the functions you suspect on the way from their last good
location to the place where they change. That should get you the function.
Once you find it, step through it a line at a time. That should get you the
location.
You don't actually need to set the breakpoints. Just single step into your
code from the last known good location. At a line or two into a function
just choose "step out".
By the way, are you using any of the C runtime functions like memcpy() and
strcpy() and their cousins? They are notorious! :-) :-(
Regards,
Will
"Tamas Demjen" <td*****@yahoo. com> wrote in message
news:uB******** ******@TK2MSFTN GP15.phx.gbl... assert(MyClass: :GetMySize() == sizeof(MyClass) );
Excellent debugging tool, thanks for the suggestion!
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: billy.becker |
last post by:
I need to save a wav file that is HTTP POSTed to a php page.
What does PHP5 do automatically to a POSTed variable when it puts it in
the $_POST superglobal array? I haven't been able to find any info on
this....
I have a script that does what I want in PERL, but I need to do it in
PHP.
I think the PERL does something magic when it does this:
|
by: BoonHead, The Lost Philosopher |
last post by:
I think the .NET framework is great!
It's nice, clean and logical; in contradiction to the old Microsoft.
It only saddens me that the new Microsoft still doesn't under stand there own rules when it comes to file paths.
A lot of Microsoft installers for example, and also installers of other companies, do not work because they handle paths in the following manner:
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: Richard Lewis Haggard |
last post by:
We are having a lot of trouble with problems relating to failures relating
to 'The located assembly's manifest definition with name 'xxx' does not
match the assembly reference" but none of us here really understand how this
could be an issue. The assemblies that the system is complaining about are
ones that we build here and we're not changing version numbers on anything.
The errors come and go with no apparent rhyme or reason.
We do not...
|
by: william |
last post by:
You guys are a great resource for learners such as I. I have seen the way
that you go over and above in explaining even the most mudane things to
beginners, and I think it is a great thing that you do here. I only hope
that you can help me understand how a certain type of application works.
I loaded an app that filters out spam (as it puts it) "before it hits your
inbox".
Now, how does this work? It changed my incoming and outgoing...
| |
by: Anoop |
last post by:
Hi,
I am new to this newsgroup and need help in the following questions.
1. I am workin' on a GUI application. Does C# provides Layout Managers the
way Java does to design GUI? I know that it can be done using the designer
but I intentionally don't want to use that. The one reason is that you
cannot change the code generated by the designer. The other could be that
you have more free hand and control to design your GUI.
2....
|
by: Cuthbert |
last post by:
After compiling the source code with gcc v.4.1.1, I got a warning
message:
"/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the
'gets' function is dangerous and should not be used."
Could anybody tell me why gets() function is dangerous??
Thank you very much.
Cuthbert
|
by: Xah Lee |
last post by:
Look at this page
http://xahlee.org/emacs/wrap-url.html
Look at it in Firebox, look at it in Safari, in Opera, and look at it
in Microsoft Internet Explorer.
The only fucked up case, is Firefox.
Namely, that it does not respect the font used when dealing with
«width:80ex».
The way to test this visually, is by this code:
<pre style="border:thin black solid;
|
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in C# in some
way? Or maybe no, because it is similar to a global variable (with its
scope restricted) which C# is dead against?
Zytan
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |