本文整理汇总了C++中SymFromAddr函数的典型用法代码示例。如果您正苦于以下问题:C++ SymFromAddr函数的具体用法?C++ SymFromAddr怎么用?C++ SymFromAddr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SymFromAddr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Func5
void Func5()
{
void *stack[1024];
unsigned short frames;
SYMBOL_INFO * symbol;
HANDLE process;
process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
frames = CaptureStackBackTrace(0, 100, stack, NULL);
symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
std::string result;
char tempStr[255];
for (int i = 0; i < frames; i++)
{
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol);
sprintf(tempStr, "%i: %s - 0x%0X\n", frames - i - 1, symbol->Name, symbol->Address);
result += tempStr;
}
free(symbol);
std::cout << result << std::endl;
}
示例2: GetSymFromAddr
BOOL GetSymFromAddr(HANDLE hProcess, DWORD64 dwAddress, LPSTR lpSymName, DWORD nSize)
{
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)malloc(sizeof(SYMBOL_INFO) + nSize * sizeof(char));
DWORD64 dwDisplacement = 0; // Displacement of the input address, relative to the start of the symbol
BOOL bRet;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = nSize;
DWORD dwOptions = SymGetOptions();
bRet = SymFromAddr(hProcess, dwAddress, &dwDisplacement, pSymbol);
if (bRet) {
// Demangle if not done already
if ((dwOptions & SYMOPT_UNDNAME) ||
UnDecorateSymbolName(pSymbol->Name, lpSymName, nSize, UNDNAME_NAME_ONLY) == 0) {
strncpy(lpSymName, pSymbol->Name, nSize);
}
}
free(pSymbol);
return bRet;
}
示例3: printStacktrace
void printStacktrace() {
// http://stackoverflow.com/questions/5693192/win32-backtrace-from-c-code
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb204633(v=vs.85).aspx
unsigned int i;
void * stack[ 100 ];
unsigned short frames;
SYMBOL_INFO * symbol;
HANDLE process;
process = GetCurrentProcess();
SymInitialize( process, NULL, TRUE );
frames = CaptureStackBackTrace( 0, 100, stack, NULL );
symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
printf("\nStacktrace\n");
for( i = 0; i < frames; i++ ) {
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
printf( "%i: %s - 0x%0X\n", frames - i - 1, symbol->Name, symbol->Address );
}
free( symbol );
}
示例4: Plookup_by_addr
int Plookup_by_addr(struct ps_prochandle *P, uintptr_t addr, char *buf, size_t size, GElf_Sym *symp)
{
SYMBOL_INFO *s;
s = (SYMBOL_INFO *) malloc(sizeof(SYMBOL_INFO) + size-1);
if (s == NULL)
return -1;
s->SizeOfStruct = sizeof(SYMBOL_INFO);
s->MaxNameLen = size;
if (SymFromAddr(P->phandle, addr, 0, s) == TRUE) {
isfunction(P, s);
symp->st_name = 0;
symp->st_info = GELF_ST_INFO((STB_GLOBAL), (STT_FUNC));
symp->st_other = 0;
symp->st_shndx = 1;
symp->st_value = s->Address;
symp->st_size = s->Size;
strncpy(buf, s->Name, size);
return 0;
}
return dw_lookup_by_addr(P, addr, buf, size, symp);
}
示例5: win_stacktrace
std::string win_stacktrace()
{
void *stack[100];
unsigned short frames = CaptureStackBackTrace(0, 100, stack, NULL);
SYMBOL_INFO *symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
HANDLE process = GetCurrentProcess();
std::string result;
result.reserve(128);
{
muduo::MutexLockGuard guard(
muduo::Singleton<win::SymManager>::instance().getMutex());
SymRefreshModuleList(process);
char buf[512];
int count = 0;
for(unsigned int i = 0; i < frames; i++)
{
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol);
count = snprintf(buf, sizeof(buf)-1,
"%i: %s - 0x%0X\n", frames-i-1, symbol->Name, symbol->Address);
if (count != -1) result.append(buf);
}
}
free(symbol);
return result;
}
示例6:
/* static */
BOOL
wxDbgHelpDLL::CallSymFromAddr(HANDLE hProcess,
DWORD64 Address,
size_t* offset,
wxString* name)
{
DWORD64 dwDisplacement;
#ifdef UNICODE
if ( SymFromAddrW )
{
VarSizedStruct<SYMBOL_INFOW> infoW;
if ( SymFromAddrW(hProcess, Address, &dwDisplacement, infoW) )
{
*offset = dwDisplacement;
*name = infoW->Name;
return TRUE;
}
}
#endif // UNICODE
if ( SymFromAddr )
{
VarSizedStruct<SYMBOL_INFO> info;
if ( SymFromAddr(hProcess, Address, &dwDisplacement, info) )
{
*offset = dwDisplacement;
*name = info->Name;
return TRUE;
}
}
return FALSE;
}
示例7: get_symbol
std::string get_symbol(void *ptr)
{
if(ptr==0)
return std::string();
init();
std::ostringstream ss;
ss << ptr;
if(syms_ready) {
DWORD64 dwDisplacement = 0;
DWORD64 dwAddress = (DWORD64)ptr;
std::vector<char> buffer(sizeof(SYMBOL_INFO) + MAX_SYM_NAME);
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)&buffer.front();
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME;
if (SymFromAddr(hProcess, dwAddress, &dwDisplacement, pSymbol))
{
ss <<": " << pSymbol->Name << std::hex << " +0x" << dwDisplacement;
}
else
{
ss << ": ???";
}
}
return ss.str();
}
示例8: formatStackTrace
std::string
formatStackTrace(StackTrace *trace)
{
auto process = GetCurrentProcess();
static bool symInitialise = false;
if (!symInitialise) {
SymInitialize(process, NULL, TRUE);
symInitialise = true;
}
auto symbol = new MySymbol();
symbol->MaxNameLen = 256;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
fmt::MemoryWriter out;
for (auto i = 0u; i < trace->frames; ++i) {
SymFromAddr(process, (DWORD64)trace->data[i], 0, symbol);
out.write("{}: {} - 0x{:X}x\n", trace->frames - i - 1, (const char*)symbol->Name, symbol->Address);
}
delete symbol;
return out.str();
}
示例9: print_address
/***********************************************************************
* print_address
*
* Print an 16- or 32-bit address, with the nearest symbol if any.
*/
void print_address(const ADDRESS64* addr, BOOLEAN with_line)
{
char buffer[sizeof(SYMBOL_INFO) + 256];
SYMBOL_INFO* si = (SYMBOL_INFO*)buffer;
void* lin = memory_to_linear_addr(addr);
DWORD64 disp64;
DWORD disp;
print_bare_address(addr);
si->SizeOfStruct = sizeof(*si);
si->MaxNameLen = 256;
if (!SymFromAddr(dbg_curr_process->handle, (DWORD_PTR)lin, &disp64, si)) return;
dbg_printf(" %s", si->Name);
if (disp64) dbg_printf("+0x%lx", (DWORD_PTR)disp64);
if (with_line)
{
IMAGEHLP_LINE il;
IMAGEHLP_MODULE im;
il.SizeOfStruct = sizeof(il);
if (SymGetLineFromAddr(dbg_curr_process->handle, (DWORD_PTR)lin, &disp, &il))
dbg_printf(" [%s:%lu]", il.FileName, il.LineNumber);
im.SizeOfStruct = sizeof(im);
if (SymGetModuleInfo(dbg_curr_process->handle, (DWORD_PTR)lin, &im))
dbg_printf(" in %s", im.ModuleName);
}
}
示例10: tracer
/*
* PrintBacktrace
* Prints a call backtrace into the logging buffer
*/
void ExceptionTracer::PrintBacktrace()
{
StackTracer tracer(this->context);
char module_name[MAX_PATH];
char sym_buffer[sizeof(SYMBOL_INFO) + symbol_max];
int backtrace_count = 0; // Num of frames traced
bool has_symbol_api = false; // True if we have the symbol API available for use
DWORD old_options; // Saves old symbol API options
SYMBOL_INFO& symbol = *(SYMBOL_INFO*)sym_buffer;
symbol.SizeOfStruct = sizeof(SYMBOL_INFO);
symbol.MaxNameLen = symbol_max;
// Tries to get the symbol api
if (SymInitialize(GetCurrentProcess(), 0, TRUE))
{
has_symbol_api = true;
old_options = SymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES | SYMOPT_NO_PROMPTS | SYMOPT_FAIL_CRITICAL_ERRORS);
}
Print("Backtrace (may be wrong):");
EnterScope();
{
// Walks on the stack until there's no frame to trace or we traced 'max_backtrace' frames
while (auto trace = tracer.Walk())
{
if (++backtrace_count >= max_backtrace)
break;
bool has_sym = false; // This EIP has a symbol associated with it?
DWORD64 displacement; // EIP displacement relative to symbol
// If we have access to the symbol api, try to get symbol name from pc (eip)
if (has_symbol_api)
has_sym = trace->pc ? !!SymFromAddr(GetCurrentProcess(), (DWORD64)trace->pc, &displacement, &symbol) : false;
// Print everything up, this.... Ew, this looks awful!
Print(backtrace_count == 1 ? "=>" : " "); // First line should have '=>' to specify where it crashed
Print("0x%p ", trace->pc); // Print EIP at frame
if (has_sym) Print("%s+0x%x ", symbol.Name, (DWORD)displacement); // Print frame func symbol
Print("in %s (+0x%x) ", // Print module
trace->module ? FindModuleName(trace->module, module_name, sizeof(module_name)) : "unknown",
(uintptr_t)(trace->pc) - (uintptr_t)(trace->module) // Module displacement
);
if (trace->frame) Print("(0x%p) ", trace->frame); // Print frame pointer
NewLine();
}
}
LeaveScope();
// Cleanup the symbol api
if (has_symbol_api)
{
SymSetOptions(old_options);
SymCleanup(GetCurrentProcess());
}
}
示例11: printStack
void printStack(void)
{
unsigned int i;
void * stack[100];
unsigned short frames;
SYMBOL_INFO * symbol;
HANDLE process;
process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
frames = CaptureStackBackTrace(0, 100, stack, NULL);
symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
IMAGEHLP_LINE64 *line = (IMAGEHLP_LINE64 *)malloc(sizeof(IMAGEHLP_LINE64));
line->SizeOfStruct = sizeof(IMAGEHLP_LINE64);
DWORD displacement;
for (i = 0; i < frames; i++)
{
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol);
SymGetLineFromAddr64(process, (DWORD64)stack[i], &displacement, line);
printf("%s %s:%i\n", symbol->Name, line->FileName, line->LineNumber);
}
free(symbol);
}
示例12: blender_crash_handler_backtrace
static void blender_crash_handler_backtrace(FILE *fp)
{
(void)fp;
#if 0
#define MAXSYMBOL 256
unsigned short i;
void *stack[SIZE];
unsigned short nframes;
SYMBOL_INFO *symbolinfo;
HANDLE process;
process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
nframes = CaptureStackBackTrace(0, SIZE, stack, NULL);
symbolinfo = MEM_callocN(sizeof(SYMBOL_INFO) + MAXSYMBOL * sizeof( char ), "crash Symbol table");
symbolinfo->MaxNameLen = MAXSYMBOL - 1;
symbolinfo->SizeOfStruct = sizeof(SYMBOL_INFO);
for (i = 0; i < nframes; i++) {
SymFromAddr(process, ( DWORD64 )( stack[ i ] ), 0, symbolinfo);
fprintf(fp, "%u: %s - 0x%0X\n", nframes - i - 1, symbolinfo->Name, symbolinfo->Address);
}
MEM_freeN(symbolinfo);
#endif
}
示例13: dumpBacktrace
void dumpBacktrace(int dumpFile, CrashData crash)
{
#ifdef Q_OS_UNIX
// Variables for storing crash info.
void* trace[BT_SIZE]; // Backtrace frames
size_t size; // The backtrace size
// Get the backtrace.
size = backtrace(trace, BT_SIZE);
// Dump the backtrace
dprintf(dumpFile, "---- BEGIN BACKTRACE ----\n");
backtrace_symbols_fd(trace, size, dumpFile);
dprintf(dumpFile, "---- END BACKTRACE ----\n");
#elif defined Q_OS_WIN32
dprintf(dumpFile, "---- BEGIN BACKTRACE ----\n");
StackFrame stack[BT_SIZE];
size_t size;
SYMBOL_INFO *symbol;
HANDLE process;
size = getBacktrace(stack, BT_SIZE, *crash.context);
// FIXME: Accessing heap memory is supposedly "dangerous",
// but I can't find another way of doing this.
// Initialize
process = GetCurrentProcess();
if (!SymInitialize(process, NULL, true))
{
dprintf(dumpFile, "Failed to initialize symbol handler. Can't print stack trace.\n");
dprintf(dumpFile, "Here's a list of addresses in the call stack instead:\n");
for(int i = 0; i < size; i++)
{
dprintf(dumpFile, "0x%0X\n", (DWORD64)stack[i].address);
}
} else {
// Allocate memory... ._.
symbol = (SYMBOL_INFO *) calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
// Dump stacktrace
for(int i = 0; i < size; i++)
{
DWORD64 addr = (DWORD64)stack[i].address;
if (!SymFromAddr(process, (DWORD64)(addr), 0, symbol))
dprintf(dumpFile, "?? - 0x%0X\n", addr);
else
dprintf(dumpFile, "%s - 0x%0X\n", symbol->Name, symbol->Address);
}
free(symbol);
}
dprintf(dumpFile, "---- END BACKTRACE ----\n");
#endif
}
示例14: _ASSERTE
bool CSymbolEngine::FindSymbolByAddress( DWORD64 Address, TString& Name, DWORD64& Displacement )
{
// Check preconditions
if( m_hProcess == NULL )
{
_ASSERTE( !_T("Symbol engine is not yet initialized.") );
m_LastError = ERROR_INVALID_FUNCTION;
return false;
}
// Look up the symbol
CSymbolInfoPackage sip; // it contains SYMBOL_INFO structure plus additional
// space for the name of the symbol
DWORD64 Disp = 0;
if( !SymFromAddr( m_hProcess, Address, &Disp, &sip.si ) )
{
// Failed, but do not assert here - it is usually normal when a symbol is not found
//m_LastError = GetLastError();
//return false;
Name = L"unknown";
Displacement = 0;
return true;
}
Name = sip.si.Name;
Displacement = Disp;
return true;
}
示例15: SymbolInfoHelper
std::string FunctionResolver::getMethodSymbolFromAddress(const ULONG64& funcAddress)
{
SymbolInfoHelper* pSymbolInfoHelper = new SymbolInfoHelper();
//PSYMBOL_INFO symbol = pSymbolInfoHelper->AllocSymbol(256);
const size_t array_size = 256;
const size_t size = sizeof(SYMBOL_INFO) + (array_size - 1) * sizeof(TCHAR);
SYMBOL_INFO* symbol = (SYMBOL_INFO*)calloc(1, size);
if (!symbol)
{
//deal with it
}
symbol->SizeOfStruct = sizeof(*symbol); //both values must
symbol->MaxNameLen = array_size; //be set by user
DWORD64 dwDisplacement = 0;
if (SymFromAddr(this->m_hProcess, funcAddress, &dwDisplacement, symbol) == FALSE)
{
return "";
}
std::string functionSymName(symbol->Name, symbol->NameLen);
delete pSymbolInfoHelper;
pSymbolInfoHelper = NULL;
return functionSymName;
}