What do the hex numbers in the "first-chance exception..." messages mean?
Asked Answered
L

1

7

For example, in the message:

First-chance exception at 0x757bd36f in foo.exe: Microsoft C++ exception: _ASExceptionInfo at memory location 0x001278cc..

What does 0x757bd36f and 0x001278cc mean? I think that 0x757bd36f would mean the EIP at the time the exception was thrown, but what about the second number?

Lobate answered 24/7, 2012 at 15:3 Comment(3)
I guess it is the place where the exception object has been allocated.Greece
It would be cool if it was that. We could then look at the data of the thrown object with the Memory window. This is useful especially for exceptions that are raised and handled internally by a library.Lobate
@satuon: Doing a bit of testing, that does seem to be the case.Sidewalk
S
2

As you've surmised, the first is the EIP when the exception happened (or RIP, for 64-it code).

Doing some testing, the second number is the address of the exception object being caught. Keep in mind, however, that this is not the same as the address of the exception object that was thrown. For example, I wrote the following bit of test code:

#include <iostream>
#include <conio.h>

class XXX { } xxx;

void thrower() { 
    throw xxx;
}

int main() {
    try {
        std::cout << "Address of xxx: " << (void *)&xxx << "\n";
        thrower();
    }
    catch(XXX const &x) {
        std::cout << "Address of x: " << (void *)&x << "\n";
    }
    getch();
    return 0;
}

At least in my testing, the second address VS shows in its "first chance exception" message matches with the address I get for x in the code above.

Sidewalk answered 24/7, 2012 at 15:6 Comment(7)
You and I both wrote the same thing, but that only applies to an access violation. This is a C++ exception (throw blah;)Oast
@BenVoigt: I just did a bit of testing, and edited the answer. If you could take a look and see if it seems improved, I'd appreciate it (and I do appreciate your comment as well).Sidewalk
Wait, isn't that exception thrown on the stack? So you receive in your catch a pointer to an address on the stack that's already unwind-ed?Lobate
@satuon: Allocation of exception objects is a little tricky. The standard pretty much keeps its hands off, saying that how the exception object is allocated is unspecified (§15.2/3, for anybody who cares). Different compilers work differently, and I haven't looked closely at how VC++ does it recently enough to say exactly how it works. Windows XP added VEH to the previous SEH, which probably affected some of this, but I'm not sure how much.Sidewalk
@Jerry: Yeah, after the edit this is a good explanation of the address shown for first-chance handling of Microsoft C++ exceptions. +1Oast
@satuon: The exception object definitely can't be stored on the stack. The lifetime rules for exception objects are complicated, and people have even used them to implement full-on thread-local storage, using only portable C++.Oast
@BenVoigt: Do you have a pointer for the thread local storage thing ?Greece

© 2022 - 2024 — McMap. All rights reserved.