ReactOS  0.4.15-dev-5492-g47f3a4e
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(fInvadeProcess)   init_sym_imp(fInvadeProcess, __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_dll (char szFile[MAX_PATH], char szPath[MAX_PATH])
 
void cleanup_msvc_dll ()
 
static HANDLE proc ()
 
static BOOL init_sym_imp (BOOL fInvadeProcess, 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 supports_pdb (HANDLE hProc, DWORD64 BaseAddress)
 
static void test_SymFromName (HANDLE hProc, DWORD64 BaseAddress)
 
static void test_SymFromAddr (HANDLE hProc, DWORD64 BaseAddress)
 
static BOOL CALLBACK EnumSymProc (PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)
 
static void test_SymEnumSymbols (HANDLE hProc, DWORD64 BaseAddress)
 
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

PfnDliHook __pfnDliFailureHook2
 
static VS_FIXEDFILEINFO dbghelpFileVer
 
static int g_SymRegisterCallbackW64NotFound = 0
 
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:975
static unsigned char buff[32768]
Definition: fatten.c:17

Definition at line 57 of file pdb.c.

◆ init_sym

#define init_sym (   fInvadeProcess)    init_sym_imp(fInvadeProcess, __FILE__, __LINE__)

Definition at line 55 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)
GLuint64EXT * result
Definition: glext.h:11304
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49

Definition at line 20 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

◆ cleanup_msvc_dll()

void cleanup_msvc_dll ( )

Definition at line 90 of file data.c.

91 {
92  char szFile[MAX_PATH];
93  BOOL ret;
94  const char* dir = tmpdir();
95 
96  sprintf(szFile, "%s\\uffs.pdb", dir);
97  ret = DeleteFileA(szFile);
98  ok(ret, "DeleteFileA failed(%d)\n", GetLastError());
99 
100  sprintf(szFile, "%s\\uffs.dll", dir);
101  ret = DeleteFileA(szFile);
102  ok(ret, "DeleteFileA failed(%d)\n", GetLastError());
104  ok(ret, "RemoveDirectoryA failed(%d)\n", GetLastError());
105 }
static const char * tmpdir()
Definition: data.c:18
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
unsigned int dir
Definition: maze.c:112
#define MAX_PATH
Definition: compat.h:34
int ret
#define ok(value,...)
Definition: atltest.h:57
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 50 of file pdb.c.

51 {
52  SymCleanup(proc());
53 }
BOOL WINAPI SymCleanup(HANDLE hProcess)
Definition: dbghelp.c:557
static HANDLE proc()
Definition: pdb.c:34

Referenced by START_TEST(), and test_SymRegCallback().

◆ DliFailHook()

FARPROC WINAPI DliFailHook ( unsigned  dliNotify,
PDelayLoadInfo  pdli 
)

Definition at line 206 of file pdb.c.

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

Referenced by START_TEST().

◆ EnumSymProc()

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

Definition at line 437 of file pdb.c.

438 {
439  test_context* ctx = UserContext;
440 
441  if (ctx->Index < ARRAYSIZE(test_data))
442  {
443  ok_ulonglong(pSymInfo->ModBase, ctx->BaseAddress);
444  ok_ulonglong(pSymInfo->Address, ctx->BaseAddress + test_data[ctx->Index].AddressOffset);
445  ok_hex(pSymInfo->Tag, test_data[ctx->Index].Tag);
446  ok_str(pSymInfo->Name, test_data[ctx->Index].Name);
447 
448  ctx->Index++;
449  }
450  else
451  {
452  ok(0, "Out of bounds (%lu), max is: %i!\n", ctx->Index, ARRAYSIZE(test_data));
453  }
454 
455  return TRUE;
456 }
ULONG Tag
Definition: compat.h:1049
CHAR Name[1]
Definition: compat.h:1052
#define ok_str(x, y)
Definition: atltest.h:127
#define TRUE
Definition: types.h:120
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
ULONG64 Address
Definition: compat.h:1046
#define ok_hex(expression, result)
Definition: atltest.h:94
ULONG64 ModBase
Definition: compat.h:1043
#define ok(value,...)
Definition: atltest.h:57
#define ok_ulonglong(expression, result)
Definition: pdb.c:20

Referenced by test_SymEnumSymbols().

◆ extract_msvc_dll()

int extract_msvc_dll ( char  szFile[MAX_PATH],
char  szPath[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  strcpy(szPath, dir);
87  return 1;
88 }
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:1040
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
unsigned int dir
Definition: maze.c:112
int ret
LPCWSTR szPath
Definition: env.c:37
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388

Referenced by START_TEST().

◆ get_module_version()

BOOL get_module_version ( _In_ HMODULE  mod,
_Out_ VS_FIXEDFILEINFO fileinfo 
)

Definition at line 64 of file pdb.c.

67 {
68  BOOL res = FALSE;
69  HRSRC hResInfo;
70  char *errmsg;
71  DWORD dwSize, errcode = 0;
72  UINT uLen;
73  HGLOBAL hResData = 0;
74  LPVOID pRes = NULL;
75  HLOCAL pResCopy = 0;
76  VS_FIXEDFILEINFO *lpFfi;
77 
78  if (fileinfo == NULL)
79  {
80  errmsg = "fileinfo is NULL.\n";
81  goto cleanup;
82  }
83 
85  if (hResInfo == 0)
86  {
87  errmsg = "FindResource failed";
89  goto cleanup;
90  }
91 
92  dwSize = SizeofResource(mod, hResInfo);
93  if (dwSize == 0)
94  {
95  errmsg = "SizeofResource failed";
97  goto cleanup;
98  }
99 
100  hResData = LoadResource(mod, hResInfo);
101  if (hResData == 0)
102  {
103  errmsg = "LoadResource failed";
104  errcode = GetLastError();
105  goto cleanup;
106  }
107 
108  pRes = LockResource(hResData);
109  if (pRes == NULL)
110  {
111  errmsg = "LockResource failed";
112  errcode = GetLastError();
113  goto cleanup;
114  }
115 
116  pResCopy = LocalAlloc(LMEM_FIXED, dwSize);
117  if (pResCopy == NULL)
118  {
119  errmsg = "LocalAlloc failed";
120  errcode = GetLastError();
121  goto cleanup;
122  }
123 
124  CopyMemory(pResCopy, pRes, dwSize);
125 
126  if (VerQueryValueW(pResCopy, L"\\", (LPVOID*)&lpFfi, &uLen))
127  {
128  *fileinfo = *lpFfi;
129  res = TRUE;
130  }
131 
132 cleanup:
133  /* cleanup */
134  if (hResData != 0)
135  FreeResource(hResData);
136  if (pResCopy != NULL)
137  LocalFree(pResCopy);
138  /* if it was good */
139  if (res == TRUE)
140  return TRUE;
141  /* failure path */
142  if (errcode == 0)
143  trace("get_module_version - %s.\n", errmsg);
144  else
145  trace("get_module_version - %s (lasterror %d).\n", errmsg, errcode);
146  return FALSE;
147 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define FindResource
Definition: winbase.h:3664
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
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
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
#define RT_VERSION
Definition: pedump.c:376
#define LMEM_FIXED
Definition: winbase.h:368
int errcode
Definition: crtdefs.h:373
#define trace
Definition: atltest.h:70
#define CopyMemory
Definition: winbase.h:1668
unsigned long DWORD
Definition: ntddk_ex.h:95
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#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:56
static int mod
Definition: i386-dis.c:1289
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1049

Referenced by init_dbghelp_version().

◆ init_dbghelp_version()

static void init_dbghelp_version ( )
static

Definition at line 150 of file pdb.c.

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

Referenced by START_TEST().

◆ init_sym_imp()

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

Definition at line 39 of file pdb.c.

40 {
41  if (!SymInitialize(proc(), NULL, fInvadeProcess))
42  {
44  ok_(file, line)(0, "Failed to init: 0x%x\n", err);
45  return FALSE;
46  }
47  return TRUE;
48 }
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
static HANDLE proc()
Definition: pdb.c:34
#define FALSE
Definition: types.h:117
BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess)
Definition: dbghelp.c:534
Definition: parser.c:48
unsigned long DWORD
Definition: ntddk_ex.h:95
#define err(...)
#define NULL
Definition: types.h:112
#define ok_(x1, x2)
Definition: atltest.h:61
Definition: fci.c:126

◆ proc()

static HANDLE proc ( )
static

Definition at line 34 of file pdb.c.

35 {
36  return GetCurrentProcess();
37 }
#define GetCurrentProcess()
Definition: compat.h:759

Referenced by __wine_msi_call_dll_function(), _call_procedure(), _CrtGetMessageBox(), _TestVesion(), abort_dochost_tasks(), add_script_runner(), AddrOf(), ATL::CImage::COMMON::AddrOf(), alloc_async_task(), build_format_strings(), CallWindowProcT(), CheckRunningDpc(), COMCTL32_SubclassProc(), DECLARE_INTERFACE_(), DefSubclassProc(), deinit_sym(), device_process_message(), download_to_cache(), dwarfargvalue(), dwarfpctoline(), EnumDateFormatsA(), EnumDateFormatsExA(), EnumDateFormatsExW(), EnumDateFormatsW(), EnumSystemLocalesEx(), EnumTimeFormatsA(), EnumTimeFormatsW(), for_each_iface(), for_each_serializable(), FTPFtw(), FTPFtwL2(), get_ndr_types_params(), get_shiminfo(), GetWindowSubclass(), gl_tab_completion(), ATL::CWndProcThunk::Init(), init_async(), init_sym_imp(), IntSyscall(), key_call(), LoadProc(), MACRO_RegisterRoutine(), 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 562 of file pdb.c.

563 {
564  char szDllName[MAX_PATH];
565  char szDllPath[MAX_PATH], szOldDir[MAX_PATH];
566  HMODULE hMod;
569 
571  Options &= ~(SYMOPT_UNDNAME);
572  //Options |= SYMOPT_DEBUG;
574 
575  if (!extract_msvc_dll(szDllName, szDllPath))
576  {
577  ok(0, "Failed extracting files\n");
578  return;
579  }
580 
582 
583  /* Register the failure hook using the magic name '__pfnDliFailureHook2'. */
585 
586  if (init_sym(FALSE))
587  {
589  BaseAddress = SymLoadModule64(proc(), NULL, szDllName, NULL, 0x600000, 0);
590  dwErr = GetLastError();
591 
592  ok_ulonglong(BaseAddress, 0x600000);
594 
595  if (BaseAddress == 0x600000)
596  {
597  trace("Module loaded by SymLoadModule64\n");
601  }
602 
603  deinit_sym();
604  }
605 
606  /* This needs to load the module by itself */
609 
610  hMod = LoadLibraryA(szDllName);
611  if (hMod)
612  {
613  BaseAddress = (DWORD64)(DWORD_PTR)hMod;
614  /* Make sure we can find the pdb */
615  GetCurrentDirectoryA(_countof(szOldDir), szOldDir);
616  SetCurrentDirectoryA(szDllPath);
617  /* Invade process */
618  if (init_sym(TRUE))
619  {
620  trace("Module loaded by LoadLibraryA\n");
624 
625  deinit_sym();
626  }
627  /* Restore working dir */
628  SetCurrentDirectoryA(szOldDir);
629 
630  FreeLibrary(hMod);
631  }
632 
634 }
FARPROC WINAPI DliFailHook(unsigned dliNotify, PDelayLoadInfo pdli)
Definition: pdb.c:206
#define ERROR_SUCCESS
Definition: deptool.c:10
static void deinit_sym()
Definition: pdb.c:50
static const WCHAR szDllName[]
Definition: sip.c:61
DWORD WINAPI SymSetOptions(DWORD opts)
Definition: dbghelp.c:585
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
static void test_SymFromName(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:236
static HANDLE proc()
Definition: pdb.c:34
static void test_SymRegCallback(HANDLE hProc, const char *szModuleName, BOOL testANSI)
Definition: pdb.c:518
#define ok_hex(expression, result)
Definition: atltest.h:94
#define FALSE
Definition: types.h:117
void cleanup_msvc_dll()
Definition: data.c:90
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
DWORD dwErr
Definition: service.c:36
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
Definition: module.c:878
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define FreeLibrary(x)
Definition: compat.h:748
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3531
#define trace
Definition: atltest.h:70
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:752
#define SYMOPT_UNDNAME
Definition: compat.h:988
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2206
uint32_t DWORD_PTR
Definition: typedefs.h:65
int extract_msvc_dll(char szFile[MAX_PATH], char szPath[MAX_PATH])
Definition: data.c:72
PfnDliHook __pfnDliFailureHook2
Definition: delayimp.h:81
uint64_t DWORD64
Definition: typedefs.h:67
static void init_dbghelp_version()
Definition: pdb.c:150
static void test_SymEnumSymbols(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:458
DWORD WINAPI SymGetOptions(void)
Definition: dbghelp.c:600
#define ok(value,...)
Definition: atltest.h:57
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2146
#define NULL
Definition: types.h:112
#define init_sym(fInvadeProcess)
Definition: pdb.c:55
#define ok_ulonglong(expression, result)
Definition: pdb.c:20
static void test_SymFromAddr(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:304

◆ supports_pdb()

static BOOL supports_pdb ( HANDLE  hProc,
DWORD64  BaseAddress 
)
static

Definition at line 223 of file pdb.c.

224 {
226  BOOL Ret;
227 
228  memset(&ModuleInfo, 0, sizeof(ModuleInfo));
229  ModuleInfo.SizeOfStruct = sizeof(ModuleInfo);
230  Ret = SymGetModuleInfo64(hProc, BaseAddress, &ModuleInfo);
231 
232  return Ret && ModuleInfo.SymType == SymPdb;
233 }
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ ULONG _Out_writes_bytes_opt_ InformationLength PAUX_MODULE_EXTENDED_INFO ModuleInfo
Definition: aux_klib.h:65
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr, PIMAGEHLP_MODULE64 ModuleInfo)
Definition: module.c:1219

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

◆ SymRegisterCallback64Proc()

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

Definition at line 494 of file pdb.c.

499 {
501  ctx = (symregcallback_context*)(ULONG_PTR)UserContext;
502 
503  if (ctx->idx > sizeof(symregcallback_test_data))
504  {
505  ok(FALSE, "SymRegisterCallback64Proc: Too many calls.\n");
506  }
507  else
508  {
509  ok(ActionCode == symregcallback_test_data[ctx->idx].ActionCode,
510  "ActionCode (idx %u) expected %u, got %u\n",
511  ctx->idx, symregcallback_test_data[ctx->idx].ActionCode, ActionCode);
512  }
513  ctx->idx++;
514 
515  return FALSE;
516 }
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
#define ok(value,...)
Definition: atltest.h:57
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 199 of file pdb.c.

200 {
202  return FALSE;
203 }
#define FALSE
Definition: types.h:117
static int g_SymRegisterCallbackW64NotFound
Definition: pdb.c:196

Referenced by DliFailHook().

◆ test_SymEnumSymbols()

static void test_SymEnumSymbols ( HANDLE  hProc,
DWORD64  BaseAddress 
)
static

Definition at line 458 of file pdb.c.

459 {
460  BOOL Ret;
462 
463  ctx.Index = 0;
464  ctx.BaseAddress = BaseAddress;
465 
466  if (!supports_pdb(hProc, ctx.BaseAddress))
467  {
468  skip("dbghelp.dll too old or cannot enumerate symbols!\n");
469  }
470  else
471  {
472  Ret = SymEnumSymbols(hProc, ctx.BaseAddress, NULL, EnumSymProc, &ctx);
473  ok_int(Ret, TRUE);
474  ok_int(ctx.Index, ARRAYSIZE(test_data));
475  }
476 }
#define TRUE
Definition: types.h:120
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok_int(expression, result)
Definition: atltest.h:134
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
BOOL WINAPI SymEnumSymbols(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask, PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback, PVOID UserContext)
Definition: symbol.c:1147
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
static BOOL CALLBACK EnumSymProc(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)
Definition: pdb.c:437
static BOOL supports_pdb(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:223

Referenced by START_TEST().

◆ test_SymFromAddr()

static void test_SymFromAddr ( HANDLE  hProc,
DWORD64  BaseAddress 
)
static

Definition at line 304 of file pdb.c.

305 {
306  BOOL Ret;
307  char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
308  PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
309 
310  DWORD64 Displacement;
311  DWORD dwErr;
312 
313  /* No address found before load address of module */
314  Displacement = 0;
315  INIT_PSYM(buffer);
316  Ret = SymFromAddr(hProc, BaseAddress -1, &Displacement, pSymbol);
317  dwErr = GetLastError();
318  ok_int(Ret, FALSE);
320 
321  /* Right at the start of the module is recognized as the first symbol found */
322  Displacement = 0;
323  INIT_PSYM(buffer);
324  Ret = SymFromAddr(hProc, BaseAddress, &Displacement, pSymbol);
325  ok_int(Ret, TRUE);
326  ok_ulonglong(Displacement, 0xffffffffffffffff);
327  ok_ulonglong(pSymbol->ModBase, BaseAddress);
328  ok_hex(pSymbol->Flags, 0);
329  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
330  ok_hex(pSymbol->Tag, SymTagFunction);
331  ok_str(pSymbol->Name, "DllMain");
332 
333  /* The actual first instruction of the function */
334  Displacement = 0;
335  INIT_PSYM(buffer);
336  Ret = SymFromAddr(hProc, BaseAddress + 0x1010, &Displacement, pSymbol);
337  ok_int(Ret, TRUE);
338  ok_ulonglong(Displacement, 0);
339  ok_ulonglong(pSymbol->ModBase, BaseAddress);
340  ok_hex(pSymbol->Flags, 0);
341  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
342  ok_hex(pSymbol->Tag, SymTagFunction);
343  ok_str(pSymbol->Name, "DllMain");
344 
345  /* The last instruction in the function */
346  Displacement = 0;
347  INIT_PSYM(buffer);
348  Ret = SymFromAddr(hProc, BaseAddress + 0x102D, &Displacement, pSymbol);
349  ok_int(Ret, TRUE);
350  ok_ulonglong(Displacement, 0x1d);
351  ok_ulonglong(pSymbol->ModBase, BaseAddress);
352  ok_hex(pSymbol->Flags, 0);
353  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
354  ok_hex(pSymbol->Tag, SymTagFunction);
355  ok_str(pSymbol->Name, "DllMain");
356 
357  /* The padding below the function */
358  Displacement = 0;
359  INIT_PSYM(buffer);
360  Ret = SymFromAddr(hProc, BaseAddress + 0x102E, &Displacement, pSymbol);
361  ok_int(Ret, TRUE);
362  ok_ulonglong(Displacement, 0x1e);
363  ok_ulonglong(pSymbol->ModBase, BaseAddress);
364  ok_hex(pSymbol->Flags, 0);
365  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
366  ok_hex(pSymbol->Tag, SymTagFunction);
367  ok_str(pSymbol->Name, "DllMain");
368 
369  /* One byte before the next function */
370  Displacement = 0;
371  INIT_PSYM(buffer);
372  Ret = SymFromAddr(hProc, BaseAddress + 0x103f, &Displacement, pSymbol);
373  ok_int(Ret, TRUE);
374  ok_ulonglong(Displacement, 0x2f);
375  ok_ulonglong(pSymbol->ModBase, BaseAddress);
376  ok_hex(pSymbol->Flags, 0);
377  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
378  ok_hex(pSymbol->Tag, SymTagFunction);
379  ok_str(pSymbol->Name, "DllMain");
380 
381  /* First byte of the next function */
382  Displacement = 0;
383  INIT_PSYM(buffer);
384  Ret = SymFromAddr(hProc, BaseAddress + 0x1040, &Displacement, pSymbol);
385  ok_int(Ret, TRUE);
386  ok_ulonglong(Displacement, 0);
387  ok_ulonglong(pSymbol->ModBase, BaseAddress);
388  ok_hex(pSymbol->Flags, 0);
389  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1040);
390  ok_hex(pSymbol->Tag, SymTagFunction);
391  ok_str(pSymbol->Name, "FfsChkdsk");
392 
393  if (!supports_pdb(hProc, BaseAddress))
394  {
395  skip("dbghelp.dll too old or cannot read this symbol!\n");
396  }
397  else
398  {
399  /* .idata */
400  Displacement = 0;
401  INIT_PSYM(buffer);
402  Ret = SymFromAddr(hProc, BaseAddress + 0x2000, &Displacement, pSymbol);
403  ok_int(Ret, TRUE);
404  ok_ulonglong(Displacement, 0);
405  ok_ulonglong(pSymbol->ModBase, BaseAddress);
406  ok_hex(pSymbol->Flags, 0);
407  ok_ulonglong(pSymbol->Address, BaseAddress + 0x2000);
408  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
409  ok_str(pSymbol->Name, "__imp__DbgPrint");
410  }
411 }
ULONG Tag
Definition: compat.h:1049
CHAR Name[1]
Definition: compat.h:1052
#define ok_str(x, y)
Definition: atltest.h:127
#define TRUE
Definition: types.h:120
ULONG Flags
Definition: compat.h:1044
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
GLuint buffer
Definition: glext.h:5915
ULONG64 Address
Definition: compat.h:1046
#define ok_hex(expression, result)
Definition: atltest.h:94
struct _SYMBOL_INFO * PSYMBOL_INFO
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG64 ModBase
Definition: compat.h:1043
#define ok_int(expression, result)
Definition: atltest.h:134
DWORD dwErr
Definition: service.c:36
char TCHAR
Definition: xmlstorage.h:189
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
struct _SYMBOL_INFO SYMBOL_INFO
#define MAX_SYM_NAME
Definition: compat.h:975
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address, DWORD64 *Displacement, PSYMBOL_INFO Symbol)
Definition: symbol.c:1263
uint64_t DWORD64
Definition: typedefs.h:67
#define INIT_PSYM(buff)
Definition: pdb.c:57
#define skip(...)
Definition: atltest.h:64
#define ok_ulonglong(expression, result)
Definition: pdb.c:20
#define ERROR_MOD_NOT_FOUND
Definition: compat.h:104
static BOOL supports_pdb(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:223

Referenced by START_TEST().

◆ test_SymFromName()

static void test_SymFromName ( HANDLE  hProc,
DWORD64  BaseAddress 
)
static

Definition at line 236 of file pdb.c.

237 {
238  BOOL Ret;
239  char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
240  PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
241 
242  if (!supports_pdb(hProc, BaseAddress))
243  {
244  skip("dbghelp.dll too old or cannot enumerate symbols!\n");
245  }
246  else
247  {
248  INIT_PSYM(buffer);
249  Ret = SymFromName(hProc, "DllMain", pSymbol);
250  ok_int(Ret, TRUE);
251  ok_ulonglong(pSymbol->ModBase, BaseAddress);
252  ok_hex(pSymbol->Flags, 0);
253  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
254  ok_hex(pSymbol->Tag, SymTagFunction);
255  ok_str(pSymbol->Name, "DllMain");
256 
257  INIT_PSYM(buffer);
258  Ret = SymFromName(hProc, "_DllMain@12", pSymbol);
259  ok_int(Ret, TRUE);
260  ok_ulonglong(pSymbol->ModBase, BaseAddress);
261  ok_hex(pSymbol->Flags, 0x400000); // ??
262  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1010);
263  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
264  ok_str(pSymbol->Name, "_DllMain@12");
265 
266  INIT_PSYM(buffer);
267  Ret = SymFromName(hProc, "FfsChkdsk", pSymbol);
268  ok_int(Ret, TRUE);
269  ok_ulonglong(pSymbol->ModBase, BaseAddress);
270  ok_hex(pSymbol->Flags, 0);
271  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1040);
272  ok_hex(pSymbol->Tag, SymTagFunction);
273  ok_str(pSymbol->Name, "FfsChkdsk");
274 
275  INIT_PSYM(buffer);
276  Ret = SymFromName(hProc, "_FfsChkdsk@24", pSymbol);
277  ok_int(Ret, TRUE);
278  ok_ulonglong(pSymbol->ModBase, BaseAddress);
279  ok_hex(pSymbol->Flags, 0x400000); // ??
280  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1040);
281  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
282  ok_str(pSymbol->Name, "_FfsChkdsk@24");
283 
284  INIT_PSYM(buffer);
285  Ret = SymFromName(hProc, "FfsFormat", pSymbol);
286  ok_int(Ret, TRUE);
287  ok_ulonglong(pSymbol->ModBase, BaseAddress);
288  ok_hex(pSymbol->Flags, 0);
289  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1070);
290  ok_hex(pSymbol->Tag, SymTagFunction);
291  ok_str(pSymbol->Name, "FfsFormat");
292 
293  INIT_PSYM(buffer);
294  Ret = SymFromName(hProc, "_FfsFormat@24", pSymbol);
295  ok_int(Ret, TRUE);
296  ok_ulonglong(pSymbol->ModBase, BaseAddress);
297  ok_hex(pSymbol->Flags, 0x400000); // ??
298  ok_ulonglong(pSymbol->Address, BaseAddress + 0x1070);
299  ok_hex(pSymbol->Tag, SymTagPublicSymbol);
300  ok_str(pSymbol->Name, "_FfsFormat@24");
301  }
302 }
ULONG Tag
Definition: compat.h:1049
CHAR Name[1]
Definition: compat.h:1052
#define ok_str(x, y)
Definition: atltest.h:127
#define TRUE
Definition: types.h:120
ULONG Flags
Definition: compat.h:1044
GLuint buffer
Definition: glext.h:5915
ULONG64 Address
Definition: compat.h:1046
#define ok_hex(expression, result)
Definition: atltest.h:94
struct _SYMBOL_INFO * PSYMBOL_INFO
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG64 ModBase
Definition: compat.h:1043
#define ok_int(expression, result)
Definition: atltest.h:134
char TCHAR
Definition: xmlstorage.h:189
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
struct _SYMBOL_INFO SYMBOL_INFO
#define MAX_SYM_NAME
Definition: compat.h:975
#define INIT_PSYM(buff)
Definition: pdb.c:57
#define skip(...)
Definition: atltest.h:64
#define ok_ulonglong(expression, result)
Definition: pdb.c:20
BOOL WINAPI SymFromName(HANDLE hProcess, PCSTR Name, PSYMBOL_INFO Symbol)
Definition: symbol.c:1392
static BOOL supports_pdb(HANDLE hProc, DWORD64 BaseAddress)
Definition: pdb.c:223

Referenced by START_TEST().

◆ test_SymRegCallback()

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

Definition at line 518 of file pdb.c.

519 {
520  BOOL Ret;
521  DWORD dwErr;
524 
525  ctx.idx = 0;
526  ctx.isANSI = testANSI;
527 
528  if (!init_sym(FALSE))
529  return;
530 
531  if (testANSI)
532  {
534  }
535  else
536  {
539  {
540  skip("SymRegisterCallbackW64 not found in dbghelp.dll\n");
541  return;
542  }
543  }
544 
545  ok_int(Ret, TRUE);
546  if (!Ret)
547  return;
548 
550  BaseAddress = SymLoadModule64(hProc, NULL, szModuleName, NULL, 0x600000, 0);
551  dwErr = GetLastError();
552 
553  ok_ulonglong(BaseAddress, 0x600000);
555 
556  /* this is what we want to test ... we expect 5 calls */
557  ok_int(ctx.idx, 5);
558 
559  deinit_sym();
560 }
#define ERROR_SUCCESS
Definition: deptool.c:10
static void deinit_sym()
Definition: pdb.c:50
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
static BOOL CALLBACK SymRegisterCallback64Proc(HANDLE hProcess, ULONG ActionCode, ULONG64 CallbackData, ULONG64 UserContext)
Definition: pdb.c:494
#define ok_hex(expression, result)
Definition: atltest.h:94
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok_int(expression, result)
Definition: atltest.h:134
DWORD dwErr
Definition: service.c:36
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
Definition: module.c:878
_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:752
unsigned __int64 ULONG64
Definition: imports.h:198
BOOL WINAPI SymRegisterCallback64(HANDLE hProcess, PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction, ULONG64 UserContext)
Definition: dbghelp.c:810
static int g_SymRegisterCallbackW64NotFound
Definition: pdb.c:196
#define NULL
Definition: types.h:112
#define init_sym(fInvadeProcess)
Definition: pdb.c:55
#define skip(...)
Definition: atltest.h:64
#define ok_ulonglong(expression, result)
Definition: pdb.c:20
LPCWSTR LPCWSTR szModuleName
Definition: env.c:37
BOOL WINAPI SymRegisterCallbackW64(HANDLE hProcess, PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction, ULONG64 UserContext)
Definition: dbghelp.c:822

Referenced by START_TEST().

Variable Documentation

◆ __pfnDliFailureHook2

PfnDliHook __pfnDliFailureHook2

Definition at line 81 of file delayimp.h.

Referenced by __delayLoadHelper2(), and START_TEST().

◆ dbghelpFileVer

VS_FIXEDFILEINFO dbghelpFileVer
static

Definition at line 149 of file pdb.c.

Referenced by init_dbghelp_version().

◆ g_SymRegisterCallbackW64NotFound

int g_SymRegisterCallbackW64NotFound = 0
static

Definition at line 196 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:977
#define CBA_READ_MEMORY
Definition: compat.h:981
#define CBA_DEFERRED_SYMBOL_LOAD_PARTIAL
Definition: compat.h:985
#define CBA_DEFERRED_SYMBOL_LOAD_START
Definition: compat.h:976
#define CBA_DEFERRED_SYMBOL_LOAD_CANCEL
Definition: compat.h:982

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().