From: Joel Brobecker <brobecker@gnat.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA] fix gdb/901 - attach to process running as service on Windows
Date: Thu, 26 Dec 2002 04:53:00 -0000 [thread overview]
Message-ID: <20021226123817.GR1137@gnat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 450 bytes --]
The following patch fixes gdb/901. I am submitting it on behalf of
Pascal Obry, who found the fix. No new regression on Windows XP.
2002-12-26 J. Brobecker <brobecker@gnat.com>
From Pascal Obry <obry@act-europe.fr>
* win32-nat.c (SetPrivilege): New routine.
(Child_Attach): call SetPrivilege to correctly set child
privileges to be able to debug applications running as services.
Ok to commit?
Thanks,
--
Joel
[-- Attachment #2: win32-nat.diff --]
[-- Type: text/plain, Size: 2609 bytes --]
Index: win32-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/win32-nat.c,v
retrieving revision 1.66
diff -c -3 -p -r1.66 win32-nat.c
*** win32-nat.c 23 Nov 2002 02:49:45 -0000 1.66
--- win32-nat.c 26 Dec 2002 12:32:02 -0000
*************** has_detach_ability (void)
*** 1374,1388 ****
--- 1374,1459 ----
return 0;
}
+ /* This routine is copied from the knowledge base of the SDK
+ see article PSS ID Number: Q131065 on http://support.microsoft.com.
+
+ This routine is used to gain the right privileges to be able to debug
+ Windows applications running as Services. */
+
+ BOOL SetPrivilege (HANDLE hToken, LPCTSTR Privilege, BOOL bEnablePrivilege)
+ {
+ TOKEN_PRIVILEGES tp;
+ LUID luid;
+ TOKEN_PRIVILEGES tpPrevious;
+ DWORD cbPrevious = sizeof (TOKEN_PRIVILEGES);
+
+ if (!LookupPrivilegeValue (NULL, Privilege, &luid))
+ return FALSE;
+
+ /* First pass. Get current privilege setting. */
+ tp.PrivilegeCount = 1;
+ tp.Privileges[0].Luid = luid;
+ tp.Privileges[0].Attributes = 0;
+
+ AdjustTokenPrivileges (hToken,
+ FALSE,
+ &tp,
+ sizeof (TOKEN_PRIVILEGES),
+ &tpPrevious,
+ &cbPrevious);
+
+ if (GetLastError() != ERROR_SUCCESS)
+ return FALSE;
+
+ /* Second pass. Set privilege based on previous setting. */
+ tpPrevious.PrivilegeCount = 1;
+ tpPrevious.Privileges[0].Luid = luid;
+
+ if (bEnablePrivilege)
+ {
+ tpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
+ }
+ else
+ {
+ tpPrevious.Privileges[0].Attributes ^=
+ (SE_PRIVILEGE_ENABLED & tpPrevious.Privileges[0].Attributes);
+ }
+
+ AdjustTokenPrivileges (hToken,
+ FALSE,
+ &tpPrevious,
+ cbPrevious,
+ NULL,
+ NULL);
+
+ if (GetLastError() != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+ }
+
/* Attach to process PID, then initialize for debugging it. */
static void
child_attach (char *args, int from_tty)
{
BOOL ok;
DWORD pid;
+ HANDLE hToken;
if (!args)
error_no_arg ("process-id to attach");
+
+ if (OpenProcessToken (GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
+ &hToken))
+ {
+ if (!SetPrivilege (hToken, SE_DEBUG_NAME, TRUE))
+ {
+ printf_unfiltered ("Failed to get SE_DEBUG_NAME priviledge");
+ printf_unfiltered ("This can cause attach to fail on Windows NT");
+ }
+ CloseHandle (hToken);
+ }
pid = strtoul (args, 0, 0);
ok = DebugActiveProcess (pid);
next reply other threads:[~2002-12-26 12:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-26 4:53 Joel Brobecker [this message]
2002-12-26 11:14 ` Christopher Faylor
2003-01-10 20:23 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20021226123817.GR1137@gnat.com \
--to=brobecker@gnat.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox