From patchwork Fri Jun 24 19:42:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 917602 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5OJq1nX023580 for ; Fri, 24 Jun 2011 19:52:21 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3CB8CA099E for ; Fri, 24 Jun 2011 12:52:01 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from cloud01.chad-versace.us (184-106-247-128.static.cloud-ips.com [184.106.247.128]) by gabe.freedesktop.org (Postfix) with ESMTP id B9AFF9EEA3; Fri, 24 Jun 2011 12:44:06 -0700 (PDT) Received: from localhost.localdomain (unknown [67.208.96.87]) by cloud01.chad-versace.us (Postfix) with ESMTPSA id 623731D4224; Fri, 24 Jun 2011 19:46:12 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jun 2011 12:42:52 -0700 Message-Id: <1308944576-12740-8-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1308944576-12740-1-git-send-email-ben@bwidawsk.net> References: <1308944576-12740-1-git-send-email-ben@bwidawsk.net> Cc: mesa-dev@lists.freedesktop.org Subject: [Intel-gfx] [PATCH 07/11] i965: attach to a listening debugger X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 24 Jun 2011 19:52:21 +0000 (UTC) Use unix domain sockets to connect to a debugger and send the information the debugger will use to properly handle debug events. Signed-off-by: Ben Widawsky --- src/mesa/drivers/dri/i965/brw_wm_debug.c | 66 ++++++++++++++++++++++++++++- 1 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_wm_debug.c b/src/mesa/drivers/dri/i965/brw_wm_debug.c index 41ee926..bc84aa0 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_debug.c +++ b/src/mesa/drivers/dri/i965/brw_wm_debug.c @@ -172,9 +172,60 @@ void brw_wm_print_program( struct brw_wm_compile *c, printf("\n"); } -/* This define should be shared with the debugger. Not sure of the best place - * for it */ -#define SCRATCH_SIZE (512 * 1024) +#define SCRATCH_SIZE (1 << 20) +#ifndef NO_DEBUGGER_LISTENING +#include +#include +#include +#include "intel_debug.h" + +static int +attach_to_debugger(int flink_handle) +{ + struct sockaddr_un addr; + struct debug_handshake dh; + int reply, fd, ret; + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd == -1) + return -1; + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, SHADER_DEBUG_SOCKET, sizeof(addr.sun_path) - 1); + + ret = connect(fd, &addr, sizeof(addr)); + if (ret == -1) + goto done; + + dh.version = DEBUG_HANDSHAKE_VERSION; + dh.flink_handle = flink_handle; + dh.per_thread_scratch = SCRATCH_SIZE; + ret = write(fd, &dh, sizeof(dh)); + if (ret != sizeof(dh)) { + ret = -1; + goto done; + } + + ret = read(fd, &reply, sizeof(reply)); + if (ret != sizeof(reply)) { + ret = -1; + goto done; + } + + if (strncmp(DEBUG_HANDSHAKE_ACK, (char *)&reply, strlen(DEBUG_HANDSHAKE_ACK))) { + ret = 1; + goto done; + } + + ret = 0; + +done: + close(fd); + return ret; +} +#endif + void brw_wm_init_debug( struct brw_context *brw, const char *sr_path ) { @@ -228,6 +279,7 @@ void brw_wm_init_debug( struct brw_context *brw, 4096); assert(brw->wm.scratch_bo); + /* Put a nice pattern in the buffer to hopefully help detect errors */ drm_intel_bo_map(brw->wm.scratch_bo, 0); memset(brw->wm.scratch_bo->virtual, 0xa5, SCRATCH_SIZE * brw->wm_max_threads); drm_intel_bo_unmap(brw->wm.scratch_bo); @@ -235,6 +287,14 @@ void brw_wm_init_debug( struct brw_context *brw, ret = drm_intel_bo_flink(brw->wm.scratch_bo, &name); assert(ret == 0); + /* Simple system routines do not need a debugger present */ + #ifndef NO_DEBUGGER_LISTENING + if (attach_to_debugger(name) != 0) { + fprintf(stderr, "Failed to attach to debugger\n"); + goto done; + } + #endif + brw->wm.debugging = GL_TRUE; done: