• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
the_edd

Help with dbghelp/imagehlp

6 posts in this topic

I have a case where [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681344%28v=vs.85%29.aspx"]SymGetSymFromAddr()[/url] says it's succeeding, but in fact it is returning an empty string for the symbol.

Here is my test case:
[code]#include <windows.h>
#include <imagehlp.h>

#include <cassert>
#include <cstddef>
#include <cstring>
#include <iostream>

struct symbol_buffer
{
static const std::size_t max_sym_length = 4096;

symbol_buffer()
{
std::memset(buffer, 0x00, sizeof buffer);

IMAGEHLP_SYMBOL *sym = get();

sym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
sym->MaxNameLength = max_sym_length;
}

IMAGEHLP_SYMBOL *get() { return reinterpret_cast<IMAGEHLP_SYMBOL *>(buffer); }

union
{
DWORD for_alignment;
unsigned char buffer[sizeof(IMAGEHLP_SYMBOL) + max_sym_length];
};
};

void print_function_name(UINT_PTR program_counter, HANDLE process)
{
const char *symbol_ptr = "???";

symbol_buffer sym_buff;

IMAGEHLP_SYMBOL *symbol = sym_buff.get();
//symbol->Address = program_counter; // don't think this is needed, but doesn't make any difference

if (SymGetSymFromAddr(process, program_counter, 0, symbol))
symbol_ptr = symbol->Name;

if (symbol_ptr)
std::cout << "function: '" << symbol_ptr << "'\n";
}

const char *splendid() { return "splendid"; }

int main()
{
const HANDLE process = GetCurrentProcess();

//SymSetOptions(
// SYMOPT_ALLOW_ABSOLUTE_SYMBOLS |
// SYMOPT_ALLOW_ZERO_ADDRESS |
// SymGetOptions()
//);

if (SymInitialize(process, 0, TRUE) == 0)
return 1;

const char *(*fp)() = &splendid;
UINT_PTR fp_val = 0;

assert(sizeof fp_val == sizeof fp);
std::memcpy(&fp_val, &fp, sizeof fp);

print_function_name(fp_val, process);

SymCleanup(process);

return 0;
}
[/code]

I am building with the Visual C++ 2010 toolchain as follows:

[code]
P:\guff>cl /nologo /EHsc /W3 /WX /GR /Zi /GS /arch:SSE2 /MTd /Oy- /c symbols.cpp /Fdsymbols.obj.pdb /Fosymbols.obj
symbols.cpp

P:\guff>link /nologo /incremental /WX symbols.obj imagehlp.lib /debug /pdb:symbols.exe.pdb /out:symbols.exe
[/code]

When running the code, the output tells me that the function name is the empty string, whereas I would have expected something like "splendid", or "splendid(void)", etc:

[code]
P:\guff>symbols
function: ''
[/code]

When stepping though the code in the Visual C++ debugger, the watch window quite happily tells me that the 'fp' variable in main() refers to "splendid(void)" as shown in the attached screenshot, so it seems the necessary symbolic information is present.

Even more curiously, if I enable global optimization by adding /GL compiler switch and replacing the /incremental linker switch with /LTCG, I get the kind of output I'd expect:

[code]
P:\guff>symbols
function: 'splendid'
[/code]

I have also tried [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681323%28v=vs.85%29.aspx"]SymFromAddr()[/url] instead of SymGetSymFromAddr(), and changing the options in the SymInitialize() (see commented-out code in main()), but the same behaviour persists.

Can anybody see what I'm doing wrong?
0

Share this post


Link to post
Share on other sites
I can't reproduce your problem. With MSVC 2010 and the exact same compiler and linker arguments I get [tt]function: 'ILT+230(?splendidYAPBDXZ)'[/tt] as output. Do you have the service pack and all the hotfixes installed?

Probably not related to your problem: is there any reason that you aren't using IMAGEHLP_SYMBOL_PACKAGE instead of your symbol_buffer struct?
2

Share this post


Link to post
Share on other sites
Thanks chaps. Good to know I haven't done anything obviously wrong. I'm struggling to find an updated dbghelp.dll, though. I've installed VS2010 SP1 and the latest debugging tools, but I still have a dll dated from 2008. I'm on an old 32bit Windows XP, so perhaps that's all I should hope for.

[quote name='SiCrane' timestamp='1346026589' post='4973619']
Do you have the service pack and all the hotfixes installed?
[/quote]
Is there a particularly relevant hotfix that you have in mind?

[quote]
Probably not related to your problem: is there any reason that you aren't using IMAGEHLP_SYMBOL_PACKAGE instead of your symbol_buffer struct?
[/quote]
Just ignorance. OTOH, it doesn't seem to be defined in the MinGW headers, so I'll have to stick the hand-rolled structure for the time being.
0

Share this post


Link to post
Share on other sites
[quote name='e?dd' timestamp='1346095800' post='4973877']
Is there a particularly relevant hotfix that you have in mind?
[/quote]
Not really, just trying to think of something that might help.
0

Share this post


Link to post
Share on other sites
[quote name='e?dd' timestamp='1346095800' post='4973877']
Thanks chaps. Good to know I haven't done anything obviously wrong. I'm struggling to find an updated dbghelp.dll, though. I've installed VS2010 SP1 and the latest debugging tools, but I still have a dll dated from 2008. I'm on an old 32bit Windows XP, so perhaps that's all I should hope for.
[/quote]
If you've installed the Debugging Tools, the updated dbghelp is in the same directory as WinDbg and them. You have to put it next to your app, it doesn't update the system32 one. You also need to link to dbghelp instead of imagehlp. Imagehlp is a known dll so it and its dependencies are loaded from system32 regardless.

The problem with the 'no-name incremental link' is that old versions of the DIA code (used in 2000/XP versions of dbghelp.dll) treated the incremental link table (the ILT in SiCrane's result) stubs as unnamed Thunk symbols. The non incremental version just has function symbols, which obviously do have names. The newer versions interpret the ILT as Public Symbols, which do have a name.

It's anybody's guess as to whether the old versions had a pdb parsing bug in regards to the ILT symbols, or whether modern PDB's have an incompatible format with that version of the parsing code. Edited by adeyblue
1

Share this post


Link to post
Share on other sites
[quote name='adeyblue' timestamp='1346102307' post='4973914']
If you've installed the Debugging Tools, the updated dbghelp is in the same directory as WinDbg and them. You have to put it next to your app, it doesn't update the system32 one. You also need to link to dbghelp instead of imagehlp. Imagehlp is a known dll so it and its dependencies are loaded from system32 regardless.
[/quote]
Splendid! :) Everything's working now, thanks.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0