diff mbox series

[1/1] e1000: Get debug flags from an environment variable

Message ID 20240329150450.2843758-2-porter@cs.unc.edu (mailing list archive)
State New, archived
Headers show
Series Upstreaming Course Debugging Changes | expand

Commit Message

Don Porter March 29, 2024, 3:04 p.m. UTC
From: Austin Clements <aclements@csail.mit.edu>

The E1000 debug messages are very useful for developing drivers, so
this introduces an E1000_DEBUG environment variable that lets the
debug flags be set without recompiling QEMU.

Signed-off-by: Austin Clements <aclements@csail.mit.edu>
[geofft@ldpreload.com: Rebased on top of 2.9.0]
Signed-off-by: Geoffrey Thomas <geofft@ldpreload.com>
Signed-off-by: Don Porter <porter@cs.unc.edu>
---
 hw/net/e1000.c | 65 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 59 insertions(+), 6 deletions(-)

Comments

Richard Henderson March 29, 2024, 5:46 p.m. UTC | #1
On 3/29/24 05:04, Don Porter wrote:
> From: Austin Clements <aclements@csail.mit.edu>
> 
> The E1000 debug messages are very useful for developing drivers, so
> this introduces an E1000_DEBUG environment variable that lets the
> debug flags be set without recompiling QEMU.
> 
> Signed-off-by: Austin Clements <aclements@csail.mit.edu>
> [geofft@ldpreload.com: Rebased on top of 2.9.0]
> Signed-off-by: Geoffrey Thomas <geofft@ldpreload.com>
> Signed-off-by: Don Porter <porter@cs.unc.edu>
...
> -/* #define E1000_DEBUG */
> -
> -#ifdef E1000_DEBUG
>   enum {
>       DEBUG_GENERAL,      DEBUG_IO,       DEBUG_MMIO,     DEBUG_INTERRUPT,
>       DEBUG_RX,           DEBUG_TX,       DEBUG_MDIC,     DEBUG_EEPROM,
>       DEBUG_UNKNOWN,      DEBUG_TXSUM,    DEBUG_TXERR,    DEBUG_RXERR,
>       DEBUG_RXFILTER,     DEBUG_PHY,      DEBUG_NOTYET,
>   };
> +
> +static const char *debugnames[] = {
> +    "GENERAL",      "IO",       "MMIO",     "INTERRUPT",
> +    "RX",           "TX",       "MDIC",     "EEPROM",
> +    "UNKNOWN",      "TXSUM",    "TXERR",    "RXERR",
> +    "RXFILTER",     "PHY",      "NOTYET",   NULL
> +};
>   #define DBGBIT(x)    (1<<DEBUG_##x)
>   static int debugflags = DBGBIT(TXERR) | DBGBIT(GENERAL);

These should be converted to tracepoints.
See docs/devel/tracing.rst.


r~
diff mbox series

Patch

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index 43f3a4a701..8d46225944 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -30,11 +30,14 @@ 
 #include "hw/pci/pci_device.h"
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
+#include "monitor/monitor.h"
 #include "net/eth.h"
 #include "net/net.h"
 #include "net/checksum.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/error-report.h"
 #include "qemu/iov.h"
 #include "qemu/module.h"
 #include "qemu/range.h"
@@ -44,15 +47,19 @@ 
 #include "trace.h"
 #include "qom/object.h"
 
-/* #define E1000_DEBUG */
-
-#ifdef E1000_DEBUG
 enum {
     DEBUG_GENERAL,      DEBUG_IO,       DEBUG_MMIO,     DEBUG_INTERRUPT,
     DEBUG_RX,           DEBUG_TX,       DEBUG_MDIC,     DEBUG_EEPROM,
     DEBUG_UNKNOWN,      DEBUG_TXSUM,    DEBUG_TXERR,    DEBUG_RXERR,
     DEBUG_RXFILTER,     DEBUG_PHY,      DEBUG_NOTYET,
 };
+
+static const char *debugnames[] = {
+    "GENERAL",      "IO",       "MMIO",     "INTERRUPT",
+    "RX",           "TX",       "MDIC",     "EEPROM",
+    "UNKNOWN",      "TXSUM",    "TXERR",    "RXERR",
+    "RXFILTER",     "PHY",      "NOTYET",   NULL
+};
 #define DBGBIT(x)    (1<<DEBUG_##x)
 static int debugflags = DBGBIT(TXERR) | DBGBIT(GENERAL);
 
@@ -60,9 +67,6 @@  static int debugflags = DBGBIT(TXERR) | DBGBIT(GENERAL);
     if (debugflags & DBGBIT(what)) \
         fprintf(stderr, "e1000: " fmt, ## __VA_ARGS__); \
     } while (0)
-#else
-#define DBGOUT(what, fmt, ...) do {} while (0)
-#endif
 
 #define IOPORT_SIZE       0x40
 #define PNPMMIO_SIZE      0x20000
@@ -1779,3 +1783,52 @@  static void e1000_register_types(void)
 }
 
 type_init(e1000_register_types)
+
+static void e1000_init_debug(void)
+{
+    const char *e1000_debug;
+    const char *p, *p1;
+    const char **debugname;
+    int i;
+
+    e1000_debug = getenv("E1000_DEBUG");
+    if (!e1000_debug || !*e1000_debug) {
+        return;
+    }
+
+    if (strcmp(e1000_debug, "?") == 0) {
+        error_printf("E1000_DEBUG flags:\n");
+        for (debugname = debugnames; *debugname; debugname++) {
+            error_printf("%s\n", *debugname);
+        }
+        exit(0);
+    }
+
+    p = e1000_debug;
+    debugflags = 0;
+    for (p = e1000_debug; ; p = p1 + 1) {
+        p1 = strchr(p, ',');
+        if (!p1) {
+            p1 = p + strlen(p);
+        }
+        for (i = 0, debugname = debugnames; *debugname; i++, debugname++) {
+            if (strlen(*debugname) == p1 - p &&
+                strncasecmp(p, *debugname, p1 - p) == 0) {
+                debugflags |= 1 << i;
+                break;
+            }
+        }
+        if (!*debugname) {
+            error_report(QERR_INVALID_PARAMETER_VALUE, "E1000_DEBUG",
+                         "a comma-separated list of E1000 debug flags");
+            error_printf_unless_qmp(
+                "Try with argument '?' for a list.\n");
+            exit(1);
+        }
+        if (*p1 != ',') {
+            break;
+        }
+    }
+}
+
+type_init(e1000_init_debug)