Skip to content

Commit ee18344

Browse files
committed
Use allocated buffer for CONTEXT
1 parent 42e97e8 commit ee18344

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

gdb/nat/windows-nat.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,23 @@ windows_process_info::pid_to_exec_file (int pid)
241241
return path;
242242
}
243243

244+
void windows_process_info::initialize_context (windows_thread_info *th)
245+
{
246+
#ifdef __x86_64__
247+
if (wow64_process)
248+
{
249+
th->context_buffer.reset (xmalloc (sizeof (WOW64_CONTEXT)));
250+
th->wow64_context = (WOW64_CONTEXT *) th->context_buffer.get ();
251+
}
252+
#endif
253+
else
254+
{
255+
th->context_buffer.reset (xmalloc (sizeof (CONTEXT)));
256+
th->context = (CONTEXT *) th->context_buffer.get ();
257+
}
258+
*context_flags_ptr (th) = 0;
259+
}
260+
244261
static std::string
245262
win32_xfer_osdata_processes ()
246263
{

gdb/nat/windows-nat.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ struct windows_thread_info
8080
/* The context of the thread, including any manipulations. */
8181
union
8282
{
83-
CONTEXT context {};
83+
CONTEXT *context = nullptr;
8484
#ifdef __x86_64__
85-
WOW64_CONTEXT wow64_context;
85+
WOW64_CONTEXT *wow64_context;
8686
#endif
8787
};
8888

@@ -105,6 +105,8 @@ struct windows_thread_info
105105

106106
/* The name of the thread. */
107107
gdb::unique_xmalloc_ptr<char> name;
108+
109+
gdb::unique_xmalloc_ptr<void> context_buffer;
108110
};
109111

110112

@@ -256,15 +258,17 @@ struct windows_process_info
256258

257259
const char *pid_to_exec_file (int);
258260

261+
void initialize_context (windows_thread_info *th);
262+
259263
template<typename Function>
260264
auto with_context (windows_thread_info *th, Function function)
261265
{
262266
#ifdef __x86_64__
263267
if (wow64_process)
264-
return function (th != nullptr ? &th->wow64_context : nullptr);
268+
return function (th != nullptr ? th->wow64_context : nullptr);
265269
else
266270
#endif
267-
return function (th != nullptr ? &th->context : nullptr);
271+
return function (th != nullptr ? th->context : nullptr);
268272
}
269273

270274
DWORD *context_flags_ptr (windows_thread_info *th)

gdb/windows-nat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ windows_nat_target::add_thread (ptid_t ptid, HANDLE h, void *tlb,
643643
base += 0x2000;
644644
#endif
645645
th = new windows_thread_info (ptid.lwp (), h, base);
646+
windows_process.initialize_context (th);
646647
windows_process.thread_list.emplace_back (th);
647648

648649
/* Add this new thread to the list of threads.

gdbserver/win32-i386-low.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ static void
284284
i386_thread_added (windows_thread_info *th)
285285
{
286286
th->debug_registers_changed = true;
287+
288+
windows_process.initialize_context (th);
287289
}
288290

289291
static void

0 commit comments

Comments
 (0)