All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Widawsky <ben@bwidawsk.net>
To: intel-gfx@lists.freedesktop.org
Cc: mesa-dev@lists.freedesktop.org, Ben Widawsky <ben@bwidawsk.net>
Subject: [PATCH 06/10] i965: attach to a listening debugger
Date: Wed, 13 Jul 2011 13:51:48 -0700	[thread overview]
Message-ID: <1310590312-21669-7-git-send-email-ben@bwidawsk.net> (raw)
In-Reply-To: <1310590312-21669-1-git-send-email-ben@bwidawsk.net>

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 <ben@bwidawsk.net>
---
 src/mesa/drivers/dri/i965/brw_wm_debug.c |   85 ++++++++++++++++++++++++++++-
 1 files changed, 82 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 cacb24a..a231d87 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_debug.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_debug.c
@@ -175,12 +175,82 @@ void brw_wm_print_program( struct brw_wm_compile *c,
 }
 
 #define SCRATCH_SIZE (512 * 1024)
+#ifndef NO_DEBUGGER_LISTENING
+#include <unistd.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include "intel_debug.h"
+
+static int
+attach_to_debugger()
+{
+   struct sockaddr_un addr;
+   int 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)
+      return ret;
+
+   return fd;
+}
+
+static int
+start_debugger(int fd, int flink_handle)
+{
+   struct debug_handshake dh;
+   int reply, ret;
+
+   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 )
 {
    struct intel_context *intel = &brw->intel;
    uint32_t name;
+   int debugger_fd;
    int ret;
 
+   /* Simple system routines do not need a debugger present */
+   #ifndef NO_DEBUGGER_LISTENING
+   if ((debugger_fd = attach_to_debugger()) < 0) {
+      fprintf(stderr, "Failed to attach to debugger\n");
+      return;
+   }
+   #endif
+
    /* In the debug case, we allocate the buffer now because we'll need to attach
     * with the debugger at a later time when flink will not work (the ring /
     * struct_mutex are likely to be frozen). If we make the buffer visible early
@@ -192,12 +262,21 @@ void brw_wm_init_debug( struct brw_context *brw )
 					   4096);
    assert(brw->wm.scratch_bo);
 
+   ret = drm_intel_bo_flink(brw->wm.scratch_bo, &name);
+   assert(ret == 0);
+
+   #ifndef NO_DEBUGGER_LISTENING
+   ret = start_debugger(debugger_fd, name);
+   if (ret != 0) {
+      drm_intel_bo_unreference(brw->wm.scratch_bo);
+      return;
+   }
+   #endif
+
+   /* 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);
 
-   ret = drm_intel_bo_flink(brw->wm.scratch_bo, &name);
-   assert(ret == 0);
-
    brw->wm.debugging = true;
 }
-- 
1.7.6

  parent reply	other threads:[~2011-07-13 20:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-13 20:51 [PATCH 0/10] fs shader debugging Ben Widawsky
2011-07-13 20:51 ` [PATCH 01/10] intel: shared header for " Ben Widawsky
2011-07-13 20:56   ` Chris Wilson
2011-07-19 21:06   ` [Intel-gfx] " Julien Cristau
2011-07-21 13:54     ` Ben Widawsky
2011-07-21 21:22       ` [Intel-gfx] " Julien Cristau
2011-07-27 15:08         ` Ben Widawsky
2011-07-27 15:16           ` Julien Cristau
2011-07-27 15:28             ` Alan Cox
2011-07-27 15:40             ` Ben Widawsky
2011-07-13 20:51 ` [PATCH 02/10] i965: copy in system routine, reserve extra scratch Ben Widawsky
2011-07-18 18:13   ` Eric Anholt
2011-07-13 20:51 ` [PATCH 03/10] i965: Reserve scratch space for debugger communication Ben Widawsky
2011-07-13 20:51 ` [PATCH 04/10] i965: setup system routine Ben Widawsky
2011-07-13 21:04   ` [Mesa-dev] " Chris Wilson
2011-07-13 20:51 ` [PATCH 05/10] i965: emit breakpoints Ben Widawsky
2011-07-13 20:51 ` Ben Widawsky [this message]
2011-07-13 20:51 ` [PATCH 07/10] intel-gpu-tools: register range handling for forcewake hooks Ben Widawsky
2011-07-13 21:15   ` Chris Wilson
2011-07-13 20:51 ` [PATCH 08/10] intel-gpu-tools/forcewaked: simple forcewake app Ben Widawsky
2011-07-13 21:18   ` Chris Wilson
2011-07-13 20:51 ` [PATCH 09/10] debugging: add important debug regs Ben Widawsky
2011-07-13 21:20   ` Chris Wilson
2011-07-13 20:51 ` [PATCH 10/10] debugging: shader debugging Ben Widawsky
2011-07-13 22:06 ` [PATCH 0/10] fs " Ben Widawsky
2011-07-17 23:25 [PATCH 00/10] fs debugging: incorporated Chris' feedback Ben Widawsky
2011-07-17 23:25 ` [PATCH 06/10] i965: attach to a listening debugger Ben Widawsky

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=1310590312-21669-7-git-send-email-ben@bwidawsk.net \
    --to=ben@bwidawsk.net \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mesa-dev@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.