Commit graph

242 commits

Author SHA1 Message Date
Alex Henrie 00df1bea9a dbghelp: Allocate real_path with the CRT and copy it to the module heap.
Fixes both a memory leak and an alloc/free mismatch, and the module heap
is the most appropriate place to hold the variable long-term.
2023-06-27 11:58:05 +02:00
Eric Pouech bbc2a9ab5b dbghelp: Implement SymSrvGetFileIndexInfo for PDB files.
Only done for DS format.

Signed-off-by: Eric Pouech <epouech@codeweavers.com>
2023-06-26 16:49:45 +02:00
Eric Pouech 5efe29edc0 dbghelp: Implement SymSrvGetFileIndexInfo for PE modules.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2023-06-20 20:29:53 +02:00
Eric Pouech 812b4b1ca3 dbghelp: Use source file path as stored in debug info format.
Currently, dbghelp returns the source file either:
- in DOS format when native module option isn't enabled
- as stored in debug info format otherwise

This used to work for PE modules inside ELF shared libraries but is broken
since evolution to REAL modules. This generates several issues:
- winedbg does not always set the native module option when calling dbghelp
  for source file related functions, leading to heterogenous output to user
- some dbghelp function rely on matching source paths, hence leading to
  errors in winedbg when mixing the two formats for the same source file.

Introduce a new Wine only dbghelp option to return the source paths as they
are stored inside debug information format, and activate it unconditionaly
inside winedbg.

This fixes some failure cases of command 'break <NN>' in winedbg.

Signed-off-by: Eric Pouech <epouech@codeweavers.com>
2023-04-18 18:17:44 +02:00
Eric Pouech 5477ee640b dbghelp: Fix vdso.so lookup.
- should have been fixed when libwine.so has been removed
- code was broken anyway
- enhanced protect against error when reading debuggee's memory

Introducing helper to correctly read pointer's from debuggee
(and other integral values).

vdso is now listed in ELF's module list (except if Wine's preloader
removes it from auxilary vector)

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2023-03-08 17:49:00 +01:00
Eric Pouech 9877ba9732 dbghelp: Don't set ELF loader when wine's loader isn't accessible.
For dbghelp in 32-bit, when accessing a live debuggee in multi-arch
configuration, Wine's ELF loader is likely mapped above 4G, hence
not accessible with 32bit Windows APIs.
So don't try to expose the ELF libraries in that case.
Introducing a new loader operation class to support live targets, for
which system operations are not accessible, but pretending they are
successful.

Note:
- when Wine's loader ELF module isn't registered by dbghelp,
  any other ELF module will not be registered by dbghelp.
- further work may be needed for winedbg in auto mode (launched with
  AeDebug key on process exception) as in that mode winedbg
  doesn't relaunch itself in 64bit, so won't be able to access
  (64bit) ELF information (in multi-arch configuration).

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2023-03-08 17:49:00 +01:00
Eric Pouech a958b5aebf dbghelp: Identify a 32bit multi-arch wow64 debuggee as a live target.
Note: from now on, winedbg will 'see' the ELF 64 bit modules (not yet
the PE ones) in multi-arch wow64 use case.
Modules can be displayed in 'info wow share' command and their debug
information is loaded.
Stack manipulation and backtracking are not available.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2023-02-06 22:34:45 +01:00
Eric Pouech aac4e9df0a dbghelp: Filter on machine when searching for Wine system PE modules.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2023-02-06 22:34:44 +01:00
Eric Pouech a89975f731 dbghelp: Expose the real path to the module in SymGetModuleInfo*().
Expose the real path of a loaded module (potentially read from
WINEDLLDIR or WINEBUILDDIR or overriden load order or ...).  This
improves gdb integration by passing the real path to the loaded
modules (instead of the paths in c:\windows\ system subdirectories).
Introduce new Wine only dbghelp's extended option to enable the
feature.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54250
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2023-01-24 18:25:58 +01:00
Alex Henrie 04225e1109 dbghelp: Annotate allocation functions with __WINE_(ALLOC_SIZE|DEALLOC|MALLOC). 2022-12-06 17:04:50 +01:00
Eric Pouech c99bafb775 dbghelp: Implement SymAddrIncludeInlineTrace().
Replacing symt_get_inlinesite_depth() with SymAddrIncludeInlineTrace()
as they look very (very) similar.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-11-18 14:11:50 +01:00
Eric Pouech 1ed24f7ec6 dbghelp: Support loading modules from Wine's multi-arch build tree.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-11-09 21:23:48 +01:00
Eric Pouech e6fd3021ba dbghelp: Added missing DECLSPEC_HIDDEN attribute.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-11-09 21:23:48 +01:00
Eric Pouech c4f1f5b185 dbghelp: Get rid of symt_inlinesite by merging it inside symt_function.
Basically:
- extending symt_function to enable storage of multiple address ranges
- symt_function and sym_inlinesite now share the same fields, so
  get rid to the later.

Note that only the first range of a top level function is actually
stored and used (even if the structure allows for more).

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-11-01 17:53:57 +01:00
Eric Pouech 790a2852aa dbghelp: Use addr_range for storing symt_function address and size.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-11-01 17:53:57 +01:00
Eric Pouech c576b0c73f dbghelp: Store address range as FAM in symt_inlinesite.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-11-01 17:53:57 +01:00
Eric Pouech a6f1f7be7e dbghelp: No longer pass inline site's address upon creation.
Instead use the first address of the first defined range of address.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-11-01 17:53:51 +01:00
Eric Pouech 363f1f49a8 dbghelp: Realloc array of buckets inside struct vector.
Instead of silently leaking no longer used chunks.
Be more robust to OOM conditions.
Introducing pool_realloc().

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-10-21 23:18:06 +02:00
Eric Pouech c5f4874e7b dbghelp: Use heap functions for allocation.
Create a dedicated heap for each module (as it was done for the
private home grown pools).

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-10-21 23:18:06 +02:00
Francois Gouget 0eb40cdbd0 dbghelp: Fix the spelling of a couple of comments. 2022-10-20 20:58:06 +02:00
Eric Pouech 3dee69106a dbghelp: Allow symt_block to be defined over non contiguous chunks.
This improves correctness of functions like SymFromAddr()
when searching local variables.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-10-19 21:07:27 +02:00
Eric Pouech 1bcdb17455 dbghelp: Remove symt_close_func_block() stabs's only parameter.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-10-10 11:11:21 +02:00
Eric Pouech b990eaa8a6 dbghelp: Expose local static variables' address.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-09-30 21:20:19 +02:00
Eric Pouech 99eb63bd7a dbghelp: Remove address field from symt_compiland.
It's mostly always set at 0, and native dbghelp doesn't expose it anyway.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
2022-09-30 21:20:09 +02:00
Eric Pouech 14462bbeab dbghelp: Let symt_basic be trans-module and nameless.
Rationale:
- native doesn't report names for SymTagBaseType objects
  => so remove typename for sym_basic
- since symt_basic becomes pretty simple, it's possible to share the object
  across all modules loaded in dbghelp (simplicity, memory usage reduction)
- removed dwarf basic types cache in dwarf.c as we now have a generic one

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2022-05-13 22:11:41 +02:00
Eric Pouech 99c7818097 dbghelp: Introduce symt_find_symbol_at().
To be used in place of symt_find_nearest().
symt_find_symbol_at() ensures that the address passed is within the
boundaries of the returned symbol (while find_nearest() doesn't).

This fixes erroneous backtraces in debugger like:
$ ./wine winedbg notepad
WineDbg starting on pid 0104
RtlDefaultNpAcl () at Z:\home\eric\work\wine\dlls\ntdll\sec.c:1731
0x00000170054805 ntdll+0x54805 [Z:\home\eric\work\wine\dlls\ntdll\sec.c:1731]: ret
1731    }
Wine-dbg>bt
Backtrace:
=>0 0x00000170054805 RtlDefaultNpAcl+0x2d5(pAcl=<internal error>) [Z:\home\eric\work\wine\dlls\ntdll\sec.c:1731] in ntdll (0x000001700701a4)
  1 0x0000017002d6c4 __wine_pop_frame(pAcl=<internal error>) [Z:\home\eric\work\wine\include\wine\exception.h:273] in ntdll (0x000001700701a4)
  2 0x0000017002d6c4 process_breakpoint+0x84() [Z:\home\eric\work\wine\dlls\ntdll\loader.c:3912] in ntdll (0x000001700701a4)
  3 0x000001700354c9 LdrInitializeThunk+0x509(context=<register R13 not accessible in this frame>, unknown2=<internal error>, unknown3=<internal error>, unknown4=<internal error>) [Z:\home\eric\work\wine\dlls\ntdll\loader.c:4200] in ntdll (0x000001700701a4)

where RtlDefaultNpAcl() has nothing to do here (it's the symbol below RIP
and we don't have a symbol with debug information for that address).

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2022-05-04 21:27:25 +02:00
Alexandre Julliard 53ab4c5385 include: Avoid Windows types in CodeView structure definitions.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2022-04-22 16:01:54 +02:00
Eric Pouech d72e6ac772 dbghelp: Attach a struct cpu* to every module.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-11-08 21:00:57 +01:00
Eric Pouech 5f9bcb13b7 mscvpdb.h: Move parsing definitions to dbghelp.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-11-02 20:32:51 +01:00
Eric Pouech 0187675065 dbghelp: Rename line_info's pc_offset field into address.
It's actually an absolute address.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-29 21:27:23 +02:00
Eric Pouech eee701ad52 dbghelp: Implement SymFromInlineContext for inlined frames.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-28 18:25:16 +02:00
Eric Pouech 82bac5d080 dbghelp: Implement StackWalkEx for inlined frames.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-28 18:25:16 +02:00
Eric Pouech fb34c82ef8 dbghelp/dwarf: Store each subrange for an inlined function.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-28 18:25:16 +02:00
Eric Pouech 690c2e51bf dbghelp/dwarf: Generate proper inline functions.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-28 18:25:16 +02:00
Eric Pouech b9290c987a dbghelp: Introduce symt_inlinesite (SymTagInlineSite) to support inline sites.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-28 18:25:16 +02:00
Eric Pouech 066bb761cc dbghelp: Add local scope information in struct process.
- make SymSetContext() generate this information
- let SymEnumSymboli() (when dealing with local symbols) use this
  information instead of the stack frame

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-27 22:40:50 +02:00
Eric Pouech 219e4b6e75 dbghelp: Implement SymFromInlineContext() when context isn't in inline mode.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-27 22:40:50 +02:00
Eric Pouech d3a876f172 dbghelp: Use wide string literals.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-19 20:55:41 +02:00
Eric Pouech 099a8bbfd3 dbghelp: Add helper to initialize a module_pair.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-13 22:52:25 +02:00
Eric Pouech b6044788ea dbghelp: Added support for custom symbols.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-06 20:29:34 +02:00
Eric Pouech dbcc714cef dbghelp: SymTagFunctionArgType's lexical parent is module, not SymTagFunctionType.
(as any other type)

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-06 20:29:34 +02:00
Eric Pouech 24a7de70a6 dbghelp: Manage parent/child relationship between SymTagExe and SymTagCompiland.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-06 20:29:34 +02:00
Eric Pouech dd67b78ed3 dbghelp/dwarf: Add support for local variables with constant values.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-28 21:48:59 +02:00
Eric Pouech d648dcd3a6 dbghelp/dwarf: Share compilation unit header information.
Store cu information for dwarf content
- in each compiland
- and queue the unique one's inside the module.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-09 22:31:54 +02:00
Eric Pouech cee52d5988 dbghelp: Get rid of useless symt_normalize_func().
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-07 23:19:22 +02:00
Eric Pouech d459301de6 dbghelp: Make symt_fill_func_line_info() and symt_get_func_line_next() static functions inside symbol.c.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-07 23:19:22 +02:00
Eric Pouech ffc3efe775 dbghelp: Manage the new MachineType field in IMAGEHLP_MODULE(W)64.
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-06 17:59:11 +02:00
Eric Pouech a4b206b384 dbghelp: Handle the case where loader isn't what WINELOADER reports.
use case, in a WoW setup:
	wine programs/winedbg/winedbg.exe.so notepad.exe
where both winedbg and notepad are 64bit exec:s

in this case, dbghelp (loaded from winedbg) reads '<...>/wine' from WINELOADER
windows env block inside notepad
(but the unix env block is correctly set to wine64 by the tweak in
ntdll/unix/loader.c)

as a consequence dbghelp doesn't get the ELF information (it tries to read 32bit
ELF entities, and fails); hence misses all the loaded ELF libraries
winedbg's command 'info share' only reports the PE modules

note: the 'dual' case
  wine64 programs/winedbg/winedbg.exe.so c:\\windows\\syswow64\\notepad.exe
  where winedbg is a 64bit exec and notepad a 32bit
  shows the same failures

workaround this in dbghelp by tweaking the value of WINELOADER whether
the debuggee is 32 or 64bit

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-03 13:51:04 +02:00
Eric Pouech c8fede5efb dbghelp: Check correctness of type (esp. in case of unknown ones).
Since with the unknown type entry, we can end up with types which don't
match the expected symt->tag, we need to check before the conversions.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-03 13:50:14 +02:00
Eric Pouech 35c45857ae dbghelp: Tidy up internals for array type.
Mainly remove hackish storage of information with negative value and
use a uniform min/count pair for all debug formats.

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-09-01 21:21:49 +02:00