Skip to content

Commit 8058bb3

Browse files
mujacicajpnurmi
andauthored
feat(screenshot): support out-of-proc capture (#1541)
* feat(screenshot): support out-of-proc capture Add a `pid` parameter to `sentry__screenshot_capture()` to allow capturing the windows of a specific process instead of always using the current process. Passing 0 preserves the existing behavior. This is needed for the upcoming native backend (#1433), where a daemon process captures screenshots on behalf of the crashed application. Partially cherry-picked from 62f1cdb (#1433) * Fix lint --------- Co-authored-by: J-P Nurmi <jpnurmi@gmail.com>
1 parent edb10f3 commit 8058bb3

5 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/backends/sentry_backend_breakpad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,
184184
sentry_attachment_t *screenshot = sentry__attachment_from_path(
185185
sentry__screenshot_get_path(options));
186186
if (screenshot
187-
&& sentry__screenshot_capture(screenshot->path)) {
187+
&& sentry__screenshot_capture(screenshot->path, 0)) {
188188
sentry__envelope_add_attachment(envelope, screenshot);
189189
}
190190
sentry__attachment_free(screenshot);

src/backends/sentry_backend_inproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ process_ucontext_deferred(const sentry_ucontext_t *uctx,
11691169
sentry_attachment_t *screenshot = sentry__attachment_from_path(
11701170
sentry__screenshot_get_path(options));
11711171
if (screenshot
1172-
&& sentry__screenshot_capture(screenshot->path)) {
1172+
&& sentry__screenshot_capture(screenshot->path, 0)) {
11731173
sentry__envelope_add_attachment(envelope, screenshot);
11741174
}
11751175
sentry__attachment_free(screenshot);

src/screenshot/sentry_screenshot_none.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include "sentry_core.h"
44

55
bool
6-
sentry__screenshot_capture(const sentry_path_t *UNUSED(path))
6+
sentry__screenshot_capture(
7+
const sentry_path_t *UNUSED(path), uint32_t UNUSED(pid))
78
{
89
return false;
910
}

src/screenshot/sentry_screenshot_windows.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,17 @@ calculate_region(DWORD pid, HRGN region)
153153
}
154154

155155
bool
156-
sentry__screenshot_capture(const sentry_path_t *path)
156+
sentry__screenshot_capture(const sentry_path_t *path, uint32_t pid)
157157
{
158158
#ifdef SENTRY_PLATFORM_XBOX
159159
(sentry_path_t *)path;
160+
(uint32_t)pid;
160161
return false;
161162
#else
163+
// Use provided PID, or current process if 0
164+
DWORD target_pid = pid ? pid : GetCurrentProcessId();
162165
HRGN region = CreateRectRgn(0, 0, 0, 0);
163-
calculate_region(GetCurrentProcessId(), region);
166+
calculate_region(target_pid, region);
164167

165168
RECT box;
166169
GetRgnBox(region, &box);

src/sentry_screenshot.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
/**
1010
* Captures a screenshot and saves it to the specified path.
1111
*
12+
* @param path The path where the screenshot should be saved.
13+
* @param pid The process ID whose windows should be captured (0 = current
14+
* process).
15+
*
1216
* Returns true if the screenshot was successfully captured and saved.
1317
*/
14-
bool sentry__screenshot_capture(const sentry_path_t *path);
18+
bool sentry__screenshot_capture(const sentry_path_t *path, uint32_t pid);
1519

1620
/**
1721
* Returns the path where a screenshot should be saved.

0 commit comments

Comments
 (0)