Skip to content

Commit

Permalink
Teach GDB about more Windows entry points
Browse files Browse the repository at this point in the history
Windows programs have several conventional entry points depending on
various circumstances. Upstream GDB is only aware of "main" and the
"start" command behaves poorly or incorrectly otherwise.
  • Loading branch information
skeeto committed Mar 12, 2023
1 parent 98a7d85 commit 3a98188
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ RUN /libiconv-$LIBICONV_VERSION/configure \
&& make install

WORKDIR /gdb
RUN sed -i 's/quiet = 0/quiet = 1/' /gdb-$GDB_VERSION/gdb/main.c \
COPY src/gdb-*.patch $PREFIX/src/
RUN cat $PREFIX/src/gdb-*.patch | patch -d/gdb-$GDB_VERSION -p1 \
&& sed -i 's/quiet = 0/quiet = 1/' /gdb-$GDB_VERSION/gdb/main.c \
&& /gdb-$GDB_VERSION/configure \
--host=$ARCH \
--with-libexpat-prefix=/deps \
Expand Down
26 changes: 26 additions & 0 deletions src/gdb-000-alternate-main.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6300,6 +6300,23 @@
if (symbol_found_p)
return;

+ if (gdbarch_osabi (target_gdbarch ()) == GDB_OSABI_WINDOWS)
+ {
+ static const char *const mains[] = {
+ "wmain", "WinMain", "wWinMain", "WinMainCRTStartup", "mainCRTStartup"
+ };
+ for (const char *main : mains)
+ {
+ struct bound_minimal_symbol msym;
+ msym = lookup_minimal_symbol (main, NULL, NULL);
+ if (msym.minsym != NULL)
+ {
+ set_main_name (main, language_unknown);
+ return;
+ }
+ }
+ }
+
set_main_name ("main", language_unknown);
}

0 comments on commit 3a98188

Please sign in to comment.