ReactOS  0.4.13-dev-257-gfabbd7c
pdb.c File Reference
#include <ntstatus.h>
#include <windows.h>
#include <dbghelp.h>
#include <cvconst.h>
#include <stdio.h>
#include <delayimp.h>
#include "wine/test.h"
Include dependency graph for pdb.c:

Go to the source code of this file.

Classes

struct  _test_context
 
struct  _test_data
 
struct  _symregcallback_context
 
struct  _symregcallback_test_data
 

Macros

#define WIN32_NO_STATUS
 
#define ok_ulonglong(expression, result)
 
#define init_sym()   init_sym_imp(__FILE__, __LINE__)
 
#define INIT_PSYM(buff)
 

Typedefs

typedef struct _test_context test_context
 
typedef struct _symregcallback_context symregcallback_context
 

Functions

void create_compressed_files ()
 
int extract_msvc_exe (char szFile[MAX_PATH])
 
void cleanup_msvc_exe ()
 
static HANDLE proc ()
 
static BOOL init_sym_imp (const char *file, int line)
 
static void deinit_sym ()
 
BOOL get_module_version (_In_ HMODULE mod, _Out_ VS_FIXEDFILEINFO *fileinfo)
 
static void init_dbghelp_version ()
 
static BOOL WINAPI SymRegisterCallbackW64_Stub (HANDLE hProcess, PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction, ULONG64 UserContext)
 
FARPROC WINAPI DliFailHook (unsigned dliNotify, PDelayLoadInfo pdli)
 
static BOOL can_enumerate (HANDLE hProc, DWORD64 BaseAddress)
 
static void test_SymFromName (HANDLE hProc, const char *szModuleName)
 
static void test_SymFromAddr (HANDLE hProc, const char *szModuleName)
 
static BOOL CALLBACK EnumSymProc (PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)
 
static void test_SymEnumSymbols (HANDLE hProc, const char *szModuleName)
 
static BOOL CALLBACK SymRegisterCallback64Proc (HANDLE hProcess, ULONG ActionCode, ULONG64 CallbackData, ULONG64 UserContext)
 
static void test_SymRegCallback (HANDLE hProc, const char *szModuleName, BOOL testANSI)
 
 START_TEST (pdb)
 

Variables

static VS_FIXEDFILEINFO dbghelpFileVer
 
static int g_SymRegisterCallbackW64NotFound = 0
 
PfnDliHook __pfnDliFailureHook2 = DliFailHook
 
static struct _test_data test_data []
 
static struct _symregcallback_test_data symregcallback_test_data []
 

Macro Definition Documentation

◆ INIT_PSYM

#define INIT_PSYM (   buff)
Value:
do { \
memset((buff), 0, sizeof((buff))); \
((PSYMBOL_INFO)(buff))->SizeOfStruct = sizeof(SYMBOL_INFO); \
((PSYMBOL_INFO)(buff))->MaxNameLen = MAX_SYM_NAME; \
} while (0)
struct _SYMBOL_INFO * PSYMBOL_INFO
#define MAX_SYM_NAME
Definition: compat.h:624
static unsigned char buff[32768]
Definition: fatten.c:17

Definition at line 55 of file pdb.c.

◆ init_sym

#define init_sym ( )    init_sym_imp(__FILE__, __LINE__)

Definition at line 53 of file pdb.c.

◆ ok_ulonglong

#define ok_ulonglong (   expression,
  result 
)
Value:
do { \
ULONG64 _value = (expression); \
ULONG64 _result = (result); \
ok(_value == (result), "Wrong value for '%s', expected: " #result " (%s), got: %s\n", \
#expression, wine_dbgstr_longlong(_result), wine_dbgstr_longlong(_value)); \
} while (0)
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
GLuint64EXT * result
Definition: glext.h:11304

Definition at line 18 of file pdb.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file pdb.c.

Typedef Documentation

◆ symregcallback_context

◆ test_context

Function Documentation

◆ can_enumerate()

static BOOL can_enumerate ( HANDLE  hProc,
DWORD64  BaseAddress 
)
static

Definition at line 225 of file pdb.c.

226 {
227  IMAGEHLP_MODULE64 ModuleInfo;
228  BOOL Ret;
229 
230  memset(&ModuleInfo, 0, sizeof(ModuleInfo));
231  ModuleInfo.SizeOfStruct = sizeof(ModuleInfo);
232  Ret = SymGetModuleInfo64(hProc, BaseAddress, &ModuleInfo);
233 
234  return Ret && ModuleInfo.SymType == SymPdb;
235 }
SYM_TYPE SymType
Definition: compat.h:885
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD SizeOfStruct
Definition: compat.h:879
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
Definition: compat.h:708
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr, PIMAGEHLP_MODULE64 ModuleInfo)
Definition: module.c:1013

Referenced by test_SymEnumSymbols(), test_SymFromAddr(), and test_SymFromName().

◆ cleanup_msvc_exe()

void cleanup_msvc_exe ( )

Definition at line 89 of file data.c.

90 {
91  char szFile[MAX_PATH];
92  BOOL ret;
93  const char* dir = tmpdir();
94 
95  sprintf(szFile, "%s\\uffs.pdb", dir);
96  ret = DeleteFileA(szFile);
97  ok(ret, "DeleteFileA failed(%d)\n", GetLastError());
98 
99  sprintf(szFile, "%s\\uffs.dll", dir);
100  ret = DeleteFileA(szFile);
101  ok(ret, "DeleteFileA failed(%d)\n", GetLastError());
103  ok(ret, "RemoveDirectoryA failed(%d)\n", GetLastError());
104 }
static const char * tmpdir()
Definition: data.c:18
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
unsigned int dir
Definition: maze.c:112
#define MAX_PATH
Definition: compat.h:26
int ret
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714

Referenced by START_TEST().

◆ create_compressed_files()

void create_compressed_files ( )

◆ deinit_sym()

static void deinit_sym ( )
static

Definition at line 48 of file pdb.c.

49 {
50  SymCleanup(proc());
51 }
BOOL WINAPI SymCleanup(HANDLE hProcess)
Definition: dbghelp.c:416
static HANDLE proc()
Definition: pdb.c:32

Referenced by test_SymEnumSymbols(), test_SymFromAddr(), test_SymFromName(), and test_SymRegCallback().

◆ DliFailHook()

FARPROC WINAPI DliFailHook ( unsigned  dliNotify,
PDelayLoadInfo  pdli 
)

Definition at line 204 of file pdb.c.

205 {
206  /* Was the failure a function, and did we get info */
207  if (dliNotify == dliFailGetProc && pdli)
208  {
209  /* Is it our function? */
210  if (pdli->dlp.fImportByName && !strcmp(pdli->dlp.szProcName, "SymRegisterCallbackW64"))
211  {
212  /* Redirect execution to the stub */
214  }
215  }
216  /* This is not the function you are looking for, continue default behavior (throw exception) */
217  return NULL;
218 }
static BOOL WINAPI SymRegisterCallbackW64_Stub(HANDLE hProcess, PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction, ULONG64 UserContext)
Definition: pdb.c:197
BOOL fImportByName
Definition: delayimp.h:57
LPCSTR szProcName
Definition: delayimp.h:60
DelayLoadProc dlp
Definition: delayimp.h:71
smooth NULL
Definition: ftsmooth.c:416
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int(* FARPROC)()
Definition: compat.h:28

◆ EnumSymProc()

static BOOL CALLBACK EnumSymProc ( PSYMBOL_INFO  pSymInfo,
ULONG  SymbolSize,
PVOID  UserContext 
)
static

Definition at line 466 of file pdb.c.

467 {
468  test_context* ctx = UserContext;
469 
470  if (ctx->Index < ARRAYSIZE(test_data))
471  {
472  ok_ulonglong(pSymInfo->ModBase, ctx->BaseAddress);
473  ok_ulonglong(pSymInfo->Address, ctx->BaseAddress + test_data[ctx->Index].AddressOffset);
474  ok_hex(pSymInfo->Tag, test_data[ctx->Index].Tag);
475  ok_str(pSymInfo->Name, test_data[ctx->Index].Name);
476 
477  ctx->Index++;
478  }
479  else
480  {
481  ok(0, "Out of bounds (%lu), max is: %i!\n", ctx->Index, ARRAYSIZE(test_data));
482  }
483 
484  return TRUE;
485 }
#define ok_str(x, y)
Definition: sprintf.c:18
ULONG Tag
Definition: compat.h:698
CHAR Name[1]
Definition: compat.h:701
#define TRUE
Definition: types.h:120
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
ULONG64 Address
Definition: compat.h:695
#define ok(value,...)
ULONG64 ModBase
Definition: compat.h:692
#define ok_hex(expression, result)
Definition: test.h:759
DWORD64 BaseAddress
Definition: pdb.c:444
#define ok_ulonglong(expression, result)
Definition: pdb.c:18
SIZE_T Index
Definition: pdb.c:445

Referenced by test_SymEnumSymbols().

◆ extract_msvc_exe()

int extract_msvc_exe ( char  szFile[MAX_PATH])

Definition at line 72 of file data.c.

73 {
74  const char* dir = tmpdir();
76  ok(ret, "CreateDirectoryA failed(%d)\n", GetLastError());
77 
78  sprintf(szFile, "%s\\uffs.pdb", dir);
79  if (!extract_one(szFile, "msvc_uffs.pdb"))
80  return 0;
81 
82  sprintf(szFile, "%s\\uffs.dll", dir);
83  if (!extract_one(szFile, "msvc_uffs.dll"))
84  return 0;
85 
86  return 1;
87 }
static int extract_one(const char *filename, const char *resid)
Definition: data.c:28
static const char * tmpdir()
Definition: data.c:18
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
smooth NULL
Definition: ftsmooth.c:416
unsigned int dir
Definition: maze.c:112
int ret

Referenced by START_TEST().

◆ get_module_version()

BOOL get_module_version ( _In_ HMODULE  mod,
_Out_ VS_FIXEDFILEINFO fileinfo 
)

Definition at line 62 of file pdb.c.

65 {
66  BOOL res = FALSE;
67  HRSRC hResInfo;
68  char *errmsg;
69  DWORD dwSize, errcode = 0;
70  UINT uLen;
71  HGLOBAL hResData = 0;
72  LPVOID pRes = NULL;
73  HLOCAL pResCopy = 0;
74  VS_FIXEDFILEINFO *lpFfi;
75 
76  if (fileinfo == NULL)
77  {
78  errmsg = "fileinfo is NULL.\n";
79  goto cleanup;
80  }
81 
83  if (hResInfo == 0)
84  {
85  errmsg = "FindResource failed";
87  goto cleanup;
88  }
89 
90  dwSize = SizeofResource(mod, hResInfo);
91  if (dwSize == 0)
92  {
93  errmsg = "SizeofResource failed";
95  goto cleanup;
96  }
97 
98  hResData = LoadResource(mod, hResInfo);
99  if (hResData == 0)
100  {
101  errmsg = "LoadResource failed";
102  errcode = GetLastError();
103  goto cleanup;
104  }
105 
106  pRes = LockResource(hResData);
107  if (pRes == NULL)
108  {
109  errmsg = "LockResource failed";
110  errcode = GetLastError();
111  goto cleanup;
112  }
113 
114  pResCopy = LocalAlloc(LMEM_FIXED, dwSize);
115  if (pResCopy == NULL)
116  {
117  errmsg = "LocalAlloc failed";
118  errcode = GetLastError();
119  goto cleanup;
120  }
121 
122  CopyMemory(pResCopy, pRes, dwSize);
123 
124  if (VerQueryValueW(pResCopy, L"\\", (LPVOID*)&lpFfi, &uLen))
125  {
126  *fileinfo = *lpFfi;
127  res = TRUE;
128  }
129 
130 cleanup:
131  /* cleanup */
132  if (hResData != 0)
133  FreeResource(hResData);
134  if (pResCopy != NULL)
135  LocalFree(pResCopy);
136  /* if it was good */
137  if (res == TRUE)
138  return TRUE;
139  /* failure path */
140  if (errcode == 0)
141  trace("get_module_version - %s.\n", errmsg);
142  else
143  trace("get_module_version - %s (lasterror %d).\n", errmsg, errcode);
144  return FALSE;
145 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define trace(...)
Definition: kmt_test.h:217
#define TRUE
Definition: types.h:120
#define FindResource
Definition: winbase.h:3607
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
#define RT_VERSION
Definition: pedump.c:376
#define LMEM_FIXED
Definition: winbase.h:349
int errcode
Definition: crtdefs.h:352
#define CopyMemory
Definition: winbase.h:1633
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
unsigned int UINT
Definition: ndis.h:50
#define VS_VERSION_INFO
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
GLuint res
Definition: glext.h:9613
char * cleanup(char *str)
Definition: wpickclick.c:99
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
static int mod
Definition: i386-dis.c:1273
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1054

Referenced by init_dbghelp_version().

◆ init_dbghelp_version()

static void init_dbghelp_version ( )
static

Definition at line 148 of file pdb.c.

149 {
151  WCHAR filenameW[MAX_PATH + 1];
152  HMODULE hDLL;
153  DWORD fileLen;
154  VS_FIXEDFILEINFO fileInfo;
155 
156  memset(&dbghelpFileVer, 0, sizeof(dbghelpFileVer));
157 
158  /* get internal file version */
159  v = ImagehlpApiVersion();
160  if (v == NULL)
161  return;
162 
163  /* get module file version */
164  hDLL = GetModuleHandleW(L"dbghelp.dll");
165  if (hDLL == 0)
166  {
167  ok(FALSE, "Dbghelp.dll is not loaded!\n");
168  return;
169  }
170  if (!get_module_version(hDLL, &fileInfo))
171  memset(&fileInfo, 0, sizeof(fileInfo));
172  dbghelpFileVer = fileInfo;
173 
174  /* get full file path */
175  fileLen = GetModuleFileNameW(hDLL, filenameW, MAX_PATH + 1);
176  if (fileLen == 0)
177  {
178  ok(FALSE, "GetModuleFileNameW for dbghelp.dll failed!\n");
179  return;
180  }
181 
182  trace("Using %S\n", filenameW);
183  trace(" API-Version: %hu.%hu.%hu (%hu)\n",
184  v->MajorVersion, v->MinorVersion, v->Revision, v->Reserved);
185 
186  trace(" Fileversion: %hu.%hu.%hu.%hu\n",
187  HIWORD(fileInfo.dwProductVersionMS),
188  LOWORD(fileInfo.dwProductVersionMS),
189  HIWORD(fileInfo.dwProductVersionLS),
190  LOWORD(fileInfo.dwProductVersionLS));
191 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
#define trace(...)
Definition: kmt_test.h:217
BOOL get_module_version(_In_ HMODULE mod, _Out_ VS_FIXEDFILEINFO *fileinfo)
Definition: pdb.c:62
static const WCHAR filenameW[]
Definition: amstream.c:41
static VS_FIXEDFILEINFO dbghelpFileVer
Definition: pdb.c:147
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
const GLdouble * v
Definition: gl.h:2040
DWORD dwProductVersionLS
Definition: compat.h:554
#define HIWORD(l)
Definition: typedefs.h:246
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
LPAPI_VERSION WINAPI ImagehlpApiVersion(VOID)
Definition: dbghelp.c:657
#define memset(x, y, z)
Definition: compat.h:39
DWORD dwProductVersionMS
Definition: compat.h:553
#define LOWORD(l)
Definition: pedump.c:82

Referenced by START_TEST().

◆ init_sym_imp()

static BOOL init_sym_imp ( const char file,
int  line 
)
static

Definition at line 37 of file pdb.c.

38 {
39  if (!SymInitialize(proc(), NULL, FALSE))
40  {
42  ok_(file, line)(0, "Failed to init: 0x%x\n", err);
43  return FALSE;
44  }
45  return TRUE;
46 }
#define TRUE
Definition: types.h:120
#define ok_(x1, x2)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static HANDLE proc()
Definition: pdb.c:32
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess)
Definition: dbghelp.c:393
Definition: parser.c:48
unsigned long DWORD
Definition: ntddk_ex.h:95
#define err(...)
Definition: fci.c:126

◆ proc()

static HANDLE proc ( )
static

Definition at line 32 of file pdb.c.

33 {
34  return GetCurrentProcess();
35 }
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168

Referenced by _call_procedure(), _TestVesion(), abort_dochost_tasks(), ACTION_CallDllFunction(), add_script_runner(), AddrOf(), ATL::CImage::COMMON::AddrOf(), alloc_async_task(), build_format_strings(), CallWindowProcT(), COMCTL32_SubclassProc(), CUSTOMPROC_wrapper(), DefSubclassProc(), deinit_sym(), device_process_message(), download_to_cache(), dwarfargvalue(), dwarfpctoline(), EnumDateFormatsA(), EnumDateFormatsExA(), EnumDateFormatsExW(), EnumDateFormatsW(), EnumSystemLocalesEx(), EnumTimeFormatsA(), EnumTimeFormatsW(), for_each_iface(), for_each_serializable(), FrLdrAddPageMapping(), FTPFtw(), FTPFtwL2(), get_ndr_types_params(), get_shiminfo(), GetWindowSubclass(), gl_tab_completion(), ATL::CWndProcThunk::Init(), init_async(), init_sym_imp(), IntSyscall(), key_call(), KiInitializeContextThread(), LoadProc(), MACRO_RegisterRoutine(), mmuaddpage(), mmugetpage(), MyUserYield(), ProcessPrefsFile(), push_dochost_task(), push_task(), readproc(), CardWindow::RegisterDropZone(), RemoveWindowSubclass(), RosSymGetAddressInformation(), rpc_broadcast(), rpc_broadcast_exp(), run_customdraw_scenario(), RunDLL(), Set(), CardRegion::SetAddCardProc(), CardButton::SetButtonProc(), CardRegion::SetClickProc(), CardRegion::SetClickReleaseProc(), CardRegion::SetDblClickProc(), CardRegion::SetDragRule(), CardRegion::SetDropRule(), CardRegion::SetRemoveCardProc(), CardWindow::SetResizeProc(), SetWindowSubclass(), START_TEST(), StubGetProcAddress(), Syscall(), test___getmainargs_parent(), test_ActiveXObject(), test_FreeLibrary(), test_GetProcAddress(), test_GetProcessHandleFromHwnd(), test_interthread_messages(), test_invalid_stdin(), Test_layers(), test_LoadLibraryA(), test_LoadLibraryExA(), test_LoadLibraryExW(), test_LoadLibraryW(), test_LresultFromObject(), test_procedures(), Test_repeatlayer(), test_stdout_handle(), test_updown_buddy(), test_wordbreak_proc(), universal(), wined3d_unregister_window(), wined3d_wndproc(), write_iface_fs(), write_param_fs(), and write_proc_func_header().

◆ START_TEST()

START_TEST ( pdb  )

Definition at line 604 of file pdb.c.

605 {
606  char szDllName[MAX_PATH];
607  //create_compressed_files();
608 
610  Options &= ~(SYMOPT_UNDNAME);
611  //Options |= SYMOPT_DEBUG;
613 
615  {
616  ok(0, "Failed extracting files\n");
617  return;
618  }
619 
621 
627 
629 
630 }
#define TRUE
Definition: types.h:120
static const WCHAR szDllName[]
Definition: sip.c:61
DWORD WINAPI SymSetOptions(DWORD opts)
Definition: dbghelp.c:443
int extract_msvc_exe(char szFile[MAX_PATH])
Definition: data.c:72
static HANDLE proc()
Definition: pdb.c:32
static void test_SymRegCallback(HANDLE hProc, const char *szModuleName, BOOL testANSI)
Definition: pdb.c:560
enum OPTION_FLAGS Options
Definition: stats.c:44
void cleanup_msvc_exe()
Definition: data.c:89
#define ok(value,...)
static void test_SymEnumSymbols(HANDLE hProc, const char *szModuleName)
Definition: pdb.c:487
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SYMOPT_UNDNAME
Definition: compat.h:637
static void test_SymFromAddr(HANDLE hProc, const char *szModuleName)
Definition: pdb.c:321
static void test_SymFromName(HANDLE hProc, const char *szModuleName)
Definition: pdb.c:238
static void init_dbghelp_version()
Definition: pdb.c:148
DWORD WINAPI SymGetOptions(void)
Definition: dbghelp.c:458

◆ SymRegisterCallback64Proc()

static BOOL CALLBACK SymRegisterCallback64Proc ( HANDLE  hProcess,
ULONG  ActionCode,
ULONG64  CallbackData,
ULONG64  UserContext 
)
static

Definition at line 536 of file pdb.c.

541 {
543  ctx = (symregcallback_context*)(ULONG_PTR)UserContext;
544 
545  if (ctx->idx > sizeof(symregcallback_test_data))
546  {
547  ok(FALSE, "SymRegisterCallback64Proc: Too many calls.\n");
548  }
549  else
550  {
551  ok(ActionCode == symregcallback_test_data[ctx->idx].ActionCode,
552  "ActionCode (idx %u) expected %u, got %u\n",
553  ctx->idx, symregcallback_test_data[ctx->idx].ActionCode, ActionCode);
554  }
555  ctx->idx++;
556 
557  return FALSE;
558 }
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define ok(value,...)
static struct _symregcallback_test_data symregcallback_test_data[]

Referenced by test_SymRegCallback().

◆ SymRegisterCallbackW64_Stub()

static BOOL WINAPI SymRegisterCallbackW64_Stub ( HANDLE  hProcess,
PSYMBOL_REGISTERED_CALLBACK64  CallbackFunction,
ULONG64  UserContext 
)
static

Definition at line 197 of file pdb.c.

198 {
200  return FALSE;
201 }
static int g_SymRegisterCallbackW64NotFound
Definition: pdb.c:194

Referenced by DliFailHook().

◆ test_SymEnumSymbols()

static void test_SymEnumSymbols ( HANDLE  hProc,
const char szModuleName 
)
static

Definition at line 487 of file pdb.c.

488 {
489  BOOL Ret;
490  DWORD dwErr;
491 
492  test_context ctx;
493 
494  if (!init_sym())
495  return;
496 
497  ctx.Index = 0;
499  ctx.BaseAddress = SymLoadModule64(hProc, NULL, szModuleName, NULL, 0x600000, 0);
500  dwErr = GetLastError();
501 
502  ok_ulonglong(ctx.BaseAddress, 0x600000);
504 
505  if (!can_enumerate(hProc, ctx.BaseAddress))
506  {
507  skip("dbghelp.dll too old or cannot enumerate symbols!\n");
508  }
509  else
510  {
511  Ret = SymEnumSymbols(hProc, ctx.BaseAddress, NULL, EnumSymProc, &ctx);
512  ok_int(Ret, TRUE);
514  }
515 
516  deinit_sym();
517 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static void deinit_sym()
Definition: pdb.c:48
#define ok_int(x, y)
Definition: sprintf.c:21
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
DWORD dwErr
Definition: service.c:36
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
Definition: module.c:673
#define ok_hex(expression, result)
Definition: test.h:759
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static BOOL can_enumerate(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:225
BOOL WINAPI SymEnumSymbols(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask, PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback, PVOID UserContext)
Definition: symbol.c:1155
#define skip(...)
DWORD64 BaseAddress
Definition: pdb.c:444
#define init_sym()
Definition: pdb.c:53
#define ok_ulonglong(expression, result)
Definition: pdb.c:18
LPCWSTR LPCWSTR szModuleName
Definition: env.c:35
static BOOL CALLBACK EnumSymProc(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)
Definition: pdb.c:466
SIZE_T Index
Definition: pdb.c:445

Referenced by START_TEST().

◆ test_SymFromAddr()

static void test_SymFromAddr ( HANDLE  hProc,
const char szModuleName 
)
static

Definition at line 321 of file pdb.c.

322 {
323  BOOL Ret;
324  char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
325  PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
326 
327  DWORD64 BaseAddress, Displacement;
328  DWORD dwErr;
329 
330  if (!init_sym())
331  return;
332 
334  BaseAddress = SymLoadModule64(hProc, NULL, szModuleName, NULL, 0x600000, 0);
335  dwErr = GetLastError();
336 
337  ok_ulonglong(BaseAddress, 0x600000);
339 
340  /* No address found before load address of module */
341  Displacement = 0;
342  INIT_PSYM(buffer);
343  Ret = SymFromAddr(hProc, BaseAddress -1, &Displacement, pSymbol);
344  dwErr = GetLastError();
345  ok_int(Ret, FALSE);
347 
348  /* Right at the start of the module is recognized as the first symbol found */
349  Displacement = 0;
350  INIT_PSYM(buffer);
351  Ret = SymFromAddr(hProc, BaseAddress, &Displacement, pSymbol);
352  ok_int(Ret, TRUE);
353  ok_ulonglong(Displacement, 0xffffffffffffffff);
354  ok_ulonglong(pSymbol->ModBase, BaseAddress);
355  ok_hex(pSymbol->Flags, 0);
356  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
357  ok_hex(pSymbol->Tag, SymTagFunction);
358  ok_str(pSymbol->Name, "DllMain");
359 
360  /* The actual first instruction of the function */
361  Displacement = 0;
362  INIT_PSYM(buffer);
363  Ret = SymFromAddr(hProc, BaseAddress + 0x1010, &Displacement, pSymbol);
364  ok_int(Ret, TRUE);
365  ok_ulonglong(Displacement, 0);
366  ok_ulonglong(pSymbol->ModBase, BaseAddress);
367  ok_hex(pSymbol->Flags, 0);
368  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
369  ok_hex(pSymbol->Tag, SymTagFunction);
370  ok_str(pSymbol->Name, "DllMain");
371 
372  /* The last instruction in the function */
373  Displacement = 0;
374  INIT_PSYM(buffer);
375  Ret = SymFromAddr(hProc, BaseAddress + 0x102D, &Displacement, pSymbol);
376  ok_int(Ret, TRUE);
377  ok_ulonglong(Displacement, 0x1d);
378  ok_ulonglong(pSymbol->ModBase, BaseAddress);
379  ok_hex(pSymbol->Flags, 0);
380  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
381  ok_hex(pSymbol->Tag, SymTagFunction);
382  ok_str(pSymbol->Name, "DllMain");
383 
384  /* The padding below the function */
385  Displacement = 0;
386  INIT_PSYM(buffer);
387  Ret = SymFromAddr(hProc, BaseAddress + 0x102E, &Displacement, pSymbol);
388  ok_int(Ret, TRUE);
389  ok_ulonglong(Displacement, 0x1e);
390  ok_ulonglong(pSymbol->ModBase, BaseAddress);
391  ok_hex(pSymbol->Flags, 0);
392  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
393  ok_hex(pSymbol->Tag, SymTagFunction);
394  ok_str(pSymbol->Name, "DllMain");
395 
396  /* One byte before the next function */
397  Displacement = 0;
398  INIT_PSYM(buffer);
399  Ret = SymFromAddr(hProc, BaseAddress + 0x103f, &Displacement, pSymbol);
400  ok_int(Ret, TRUE);
401  ok_ulonglong(Displacement, 0x2f);
402  ok_ulonglong(pSymbol->ModBase, BaseAddress);
403  ok_hex(pSymbol->Flags, 0);
404  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
405  ok_hex(pSymbol->Tag, SymTagFunction);
406  ok_str(pSymbol->Name, "DllMain");
407 
408  /* First byte of the next function */
409  Displacement = 0;
410  INIT_PSYM(buffer);
411  Ret = SymFromAddr(hProc, BaseAddress + 0x1040, &Displacement, pSymbol);
412  ok_int(Ret, TRUE);
413  ok_ulonglong(Displacement, 0);
414  ok_ulonglong(pSymbol->ModBase, BaseAddress);
415  ok_hex(pSymbol->Flags, 0);
416  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1040);
417  ok_hex(pSymbol->Tag, SymTagFunction);
418  ok_str(pSymbol->Name, "FfsChkdsk");
419 
420  if (!can_enumerate(hProc, BaseAddress))
421  {
422  skip("dbghelp.dll too old or cannot read this symbol!\n");
423  }
424  else
425  {
426  /* .idata */
427  Displacement = 0;
428  INIT_PSYM(buffer);
429  Ret = SymFromAddr(hProc, BaseAddress + 0x2000, &Displacement, pSymbol);
430  ok_int(Ret, TRUE);
431  ok_ulonglong(Displacement, 0);
432  ok_ulonglong(pSymbol->ModBase, BaseAddress);
433  ok_hex(pSymbol->Flags, 0);
434  ok_ulonglong(pSymbol->Address, BaseAddress + 0x2000);
435  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
436  ok_str(pSymbol->Name, "__imp__DbgPrint");
437  }
438 
439  deinit_sym();
440 }
#define ok_str(x, y)
Definition: sprintf.c:18
ULONG Tag
Definition: compat.h:698
CHAR Name[1]
Definition: compat.h:701
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static void deinit_sym()
Definition: pdb.c:48
#define ok_int(x, y)
Definition: sprintf.c:21
ULONG Flags
Definition: compat.h:693
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
ULONG64 Address
Definition: compat.h:695
struct _SYMBOL_INFO * PSYMBOL_INFO
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG64 ModBase
Definition: compat.h:692
smooth NULL
Definition: ftsmooth.c:416
DWORD dwErr
Definition: service.c:36
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
Definition: module.c:673
char TCHAR
Definition: xmlstorage.h:189
#define ok_hex(expression, result)
Definition: test.h:759
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
struct _SYMBOL_INFO SYMBOL_INFO
#define MAX_SYM_NAME
Definition: compat.h:624
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static BOOL can_enumerate(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:225
BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address, DWORD64 *Displacement, PSYMBOL_INFO Symbol)
Definition: symbol.c:1271
uint64_t DWORD64
Definition: typedefs.h:65
#define INIT_PSYM(buff)
Definition: pdb.c:55
#define skip(...)
#define init_sym()
Definition: pdb.c:53
#define ok_ulonglong(expression, result)
Definition: pdb.c:18
#define ERROR_MOD_NOT_FOUND
Definition: compat.h:94
LPCWSTR LPCWSTR szModuleName
Definition: env.c:35

Referenced by START_TEST().

◆ test_SymFromName()

static void test_SymFromName ( HANDLE  hProc,
const char szModuleName 
)
static

Definition at line 238 of file pdb.c.

239 {
240  BOOL Ret;
241  char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
242  PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
243 
245  DWORD dwErr;
246 
247  if (!init_sym())
248  return;
249 
251  BaseAddress = SymLoadModule64(hProc, NULL, szModuleName, NULL, 0x600000, 0);
252  dwErr = GetLastError();
253 
254  ok_ulonglong(BaseAddress, 0x600000);
256 
257  if (!can_enumerate(hProc, BaseAddress))
258  {
259  skip("dbghelp.dll too old or cannot enumerate symbols!\n");
260  }
261  else
262  {
263  INIT_PSYM(buffer);
264  Ret = SymFromName(hProc, "DllMain", pSymbol);
265  ok_int(Ret, TRUE);
266  ok_ulonglong(pSymbol->ModBase, BaseAddress);
267  ok_hex(pSymbol->Flags, 0);
268  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
269  ok_hex(pSymbol->Tag, SymTagFunction);
270  ok_str(pSymbol->Name, "DllMain");
271 
272  INIT_PSYM(buffer);
273  Ret = SymFromName(hProc, "_DllMain@12", pSymbol);
274  ok_int(Ret, TRUE);
275  ok_ulonglong(pSymbol->ModBase, BaseAddress);
276  ok_hex(pSymbol->Flags, 0x400000); // ??
277  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
278  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
279  ok_str(pSymbol->Name, "_DllMain@12");
280 
281  INIT_PSYM(buffer);
282  Ret = SymFromName(hProc, "FfsChkdsk", pSymbol);
283  ok_int(Ret, TRUE);
284  ok_ulonglong(pSymbol->ModBase, BaseAddress);
285  ok_hex(pSymbol->Flags, 0);
286  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1040);
287  ok_hex(pSymbol->Tag, SymTagFunction);
288  ok_str(pSymbol->Name, "FfsChkdsk");
289 
290  INIT_PSYM(buffer);
291  Ret = SymFromName(hProc, "_FfsChkdsk@24", pSymbol);
292  ok_int(Ret, TRUE);
293  ok_ulonglong(pSymbol->ModBase, BaseAddress);
294  ok_hex(pSymbol->Flags, 0x400000); // ??
295  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1040);
296  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
297  ok_str(pSymbol->Name, "_FfsChkdsk@24");
298 
299  INIT_PSYM(buffer);
300  Ret = SymFromName(hProc, "FfsFormat", pSymbol);
301  ok_int(Ret, TRUE);
302  ok_ulonglong(pSymbol->ModBase, BaseAddress);
303  ok_hex(pSymbol->Flags, 0);
304  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1070);
305  ok_hex(pSymbol->Tag, SymTagFunction);
306  ok_str(pSymbol->Name, "FfsFormat");
307 
308  INIT_PSYM(buffer);
309  Ret = SymFromName(hProc, "_FfsFormat@24", pSymbol);
310  ok_int(Ret, TRUE);
311  ok_ulonglong(pSymbol->ModBase, BaseAddress);
312  ok_hex(pSymbol->Flags, 0x400000); // ??
313  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1070);
314  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
315  ok_str(pSymbol->Name, "_FfsFormat@24");
316  }
317 
318  deinit_sym();
319 }
#define ok_str(x, y)
Definition: sprintf.c:18
ULONG Tag
Definition: compat.h:698
CHAR Name[1]
Definition: compat.h:701
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static void deinit_sym()
Definition: pdb.c:48
#define ok_int(x, y)
Definition: sprintf.c:21
ULONG Flags
Definition: compat.h:693
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
ULONG64 Address
Definition: compat.h:695
struct _SYMBOL_INFO * PSYMBOL_INFO
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG64 ModBase
Definition: compat.h:692
smooth NULL
Definition: ftsmooth.c:416
DWORD dwErr
Definition: service.c:36
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
Definition: module.c:673
char TCHAR
Definition: xmlstorage.h:189
#define ok_hex(expression, result)
Definition: test.h:759
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
struct _SYMBOL_INFO SYMBOL_INFO
#define MAX_SYM_NAME
Definition: compat.h:624
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static BOOL can_enumerate(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:225
uint64_t DWORD64
Definition: typedefs.h:65
#define INIT_PSYM(buff)
Definition: pdb.c:55
#define skip(...)
#define init_sym()
Definition: pdb.c:53
#define ok_ulonglong(expression, result)
Definition: pdb.c:18
BOOL WINAPI SymFromName(HANDLE hProcess, PCSTR Name, PSYMBOL_INFO Symbol)
Definition: symbol.c:1400
LPCWSTR LPCWSTR szModuleName
Definition: env.c:35

Referenced by START_TEST().

◆ test_SymRegCallback()

static void test_SymRegCallback ( HANDLE  hProc,
const char szModuleName,
BOOL  testANSI 
)
static

Definition at line 560 of file pdb.c.

561 {
562  BOOL Ret;
563  DWORD dwErr;
566 
567  ctx.idx = 0;
568  ctx.isANSI = testANSI;
569 
570  if (!init_sym())
571  return;
572 
573  if (testANSI)
574  {
576  }
577  else
578  {
581  {
582  skip("SymRegisterCallbackW64 not found in dbghelp.dll\n");
583  return;
584  }
585  }
586 
587  ok_int(Ret, TRUE);
588  if (!Ret)
589  return;
590 
592  BaseAddress = SymLoadModule64(hProc, NULL, szModuleName, NULL, 0x600000, 0);
593  dwErr = GetLastError();
594 
595  ok_ulonglong(BaseAddress, 0x600000);
597 
598  /* this is what we want to test ... we expect 5 calls */
599  ok_int(ctx.idx, 5);
600 
601  deinit_sym();
602 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static void deinit_sym()
Definition: pdb.c:48
#define ok_int(x, y)
Definition: sprintf.c:21
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static BOOL CALLBACK SymRegisterCallback64Proc(HANDLE hProcess, ULONG ActionCode, ULONG64 CallbackData, ULONG64 UserContext)
Definition: pdb.c:536
uint32_t ULONG_PTR
Definition: typedefs.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI SymRegisterCallback64(HANDLE hProcess, PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction, ULONG64 UserContext)
Definition: dbghelp.c:630
smooth NULL
Definition: ftsmooth.c:416
DWORD dwErr
Definition: service.c:36
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
Definition: module.c:673
BOOL WINAPI SymRegisterCallbackW64(HANDLE hProcess, PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction, ULONG64 UserContext)
Definition: dbghelp.c:642
#define ok_hex(expression, result)
Definition: test.h:759
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
unsigned __int64 ULONG64
Definition: imports.h:198
static int g_SymRegisterCallbackW64NotFound
Definition: pdb.c:194
#define skip(...)
#define init_sym()
Definition: pdb.c:53
#define ok_ulonglong(expression, result)
Definition: pdb.c:18
LPCWSTR LPCWSTR szModuleName
Definition: env.c:35

Referenced by START_TEST().

Variable Documentation

◆ __pfnDliFailureHook2

PfnDliHook __pfnDliFailureHook2 = DliFailHook

Definition at line 221 of file pdb.c.

Referenced by START_TEST().

◆ dbghelpFileVer

VS_FIXEDFILEINFO dbghelpFileVer
static

Definition at line 147 of file pdb.c.

Referenced by init_dbghelp_version().

◆ g_SymRegisterCallbackW64NotFound

int g_SymRegisterCallbackW64NotFound = 0
static

Definition at line 194 of file pdb.c.

Referenced by SymRegisterCallbackW64_Stub(), and test_SymRegCallback().

◆ symregcallback_test_data

struct _symregcallback_test_data symregcallback_test_data[]
static
Initial value:
= {
}
#define CBA_DEFERRED_SYMBOL_LOAD_COMPLETE
Definition: compat.h:626
#define CBA_READ_MEMORY
Definition: compat.h:630
#define CBA_DEFERRED_SYMBOL_LOAD_PARTIAL
Definition: compat.h:634
#define CBA_DEFERRED_SYMBOL_LOAD_START
Definition: compat.h:625
#define CBA_DEFERRED_SYMBOL_LOAD_CANCEL
Definition: compat.h:631

Referenced by SymRegisterCallback64Proc().

◆ test_data

Initial value:
= {
{ 0x1070, 36, SymTagFunction, "FfsFormat" },
{ 0x1010, 32, SymTagFunction, "DllMain" },
{ 0x1040, 36, SymTagFunction, "FfsChkdsk" },
{ 0x2100, 0, SymTagPublicSymbol, "__IMPORT_DESCRIPTOR_ntdll" },
{ 0x109a, 0, SymTagPublicSymbol, "_DbgPrint" },
{ 0x2004, 0, SymTagPublicSymbol, "\x7fntdll_NULL_THUNK_DATA" },
{ 0x2000, 0, SymTagPublicSymbol, "__imp__DbgPrint" },
{ 0x2114, 0, SymTagPublicSymbol, "__NULL_IMPORT_DESCRIPTOR" },
}

Referenced by run_from_file(), test_D3DKMTCreateDCFromMemory(), test_emf_WorldTransform(), test_IdnToAscii(), test_IdnToNameprepUnicode(), and test_IdnToUnicode().