aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-09-07 14:41:52 -0600
committerTom Tromey <tromey@adacore.com>2022-06-07 09:59:40 -0600
commit8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008 (patch)
tree56272b04e80d52f561d31267d0e719db65227ea0 /gdb/nat
parent265aa48b392cda4355b5875fde46b59c271cc093 (diff)
downloadgdb-8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008.zip
gdb-8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008.tar.gz
gdb-8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008.tar.bz2
Introduce wrapper for CreateProcess
This is a small refactoring that introduces a wrapper for the Windows CreateProcess function. This is done to make the next patch a bit simpler.
Diffstat (limited to 'gdb/nat')
-rw-r--r--gdb/nat/windows-nat.c51
-rw-r--r--gdb/nat/windows-nat.h15
2 files changed, 66 insertions, 0 deletions
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index ca6a529..8048344 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -741,6 +741,57 @@ wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout)
return result;
}
+/* Helper template for the CreateProcess wrappers. */
+template<typename FUNC, typename CHAR, typename INFO>
+BOOL
+create_process_wrapper (FUNC *do_create_process, const CHAR *image,
+ CHAR *command_line, DWORD flags,
+ void *environment, const CHAR *cur_dir,
+ INFO *startup_info,
+ PROCESS_INFORMATION *process_info)
+{
+ return do_create_process (image,
+ command_line, /* command line */
+ nullptr, /* Security */
+ nullptr, /* thread */
+ TRUE, /* inherit handles */
+ flags, /* start flags */
+ environment, /* environment */
+ cur_dir, /* current directory */
+ startup_info,
+ process_info);
+}
+
+/* See nat/windows-nat.h. */
+
+BOOL
+create_process (const char *image, char *command_line, DWORD flags,
+ void *environment, const char *cur_dir,
+ STARTUPINFOA *startup_info,
+ PROCESS_INFORMATION *process_info)
+{
+ return create_process_wrapper (CreateProcessA, image, command_line, flags,
+ environment, cur_dir,
+ startup_info, process_info);
+}
+
+#ifdef __CYGWIN__
+
+/* See nat/windows-nat.h. */
+
+BOOL
+create_process (const wchar_t *image, wchar_t *command_line, DWORD flags,
+ void *environment, const wchar_t *cur_dir,
+ STARTUPINFOW *startup_info,
+ PROCESS_INFORMATION *process_info);
+{
+ return create_process_wrapper (CreateProcessW, image, command_line, flags,
+ environment, cur_dir,
+ startup_info, process_info);
+}
+
+#endif /* __CYGWIN__ */
+
/* Define dummy functions which always return error for the rare cases where
these functions could not be found. */
template<typename... T>
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 450ba69..d8c498e 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -294,6 +294,21 @@ extern BOOL continue_last_debug_event (DWORD continue_status,
extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout);
+/* Wrappers for CreateProcess. */
+
+extern BOOL create_process (const char *image, char *command_line,
+ DWORD flags, void *environment,
+ const char *cur_dir,
+ STARTUPINFOA *startup_info,
+ PROCESS_INFORMATION *process_info);
+#ifdef __CYGWIN__
+extern BOOL create_process (const wchar_t *image, wchar_t *command_line,
+ DWORD flags, void *environment,
+ const wchar_t *cur_dir,
+ STARTUPINFOW *startup_info,
+ PROCESS_INFORMATION *process_info);
+#endif /* __CYGWIN__ */
+
#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
#define DebugBreakProcess dyn_DebugBreakProcess