This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 3b7dc6e8fe152b06e4acaac63fbecc1e0af511ae
Author: yinshengkai <[email protected]>
AuthorDate: Mon May 19 18:04:34 2025 +0800

    system/trace: trace dump supports specifying devices
    
    trace dump always read /dev/note/ram.  Read /dev/note/<name> instead,
    where <name> is the note driver given with -n; the name now defaults to
    "ram".
    
    Name the size of the read buffer TRACE_DUMP_BUFFER_SIZE and pass it to
    read(): the sizeof of the buffer is the size of a pointer since the
    buffer is allocated.
    
    Assisted-by: Kiro:claude-opus-5-5
    Signed-off-by: yinshengkai <[email protected]>
---
 system/trace/trace.c      |  5 ++---
 system/trace/trace.h      |  2 +-
 system/trace/trace_dump.c | 20 ++++++++++++++------
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/system/trace/trace.c b/system/trace/trace.c
index f414c41ea..729142e30 100644
--- a/system/trace/trace.c
+++ b/system/trace/trace.c
@@ -209,7 +209,7 @@ static int trace_cmd_dump(FAR const char *name, int index, 
int argc,
 
   /* Dump the trace data */
 
-  ret = trace_dump(out, binary);
+  ret = trace_dump(name, out, binary);
 
   if (changed)
     {
@@ -851,7 +851,7 @@ int main(int argc, FAR char *argv[])
   int notectlfd;
   int exitcode = EXIT_FAILURE;
   int i;
-  char name[NAME_MAX];
+  char name[NAME_MAX] = "ram";
 
   /* Open note control device */
 
@@ -863,7 +863,6 @@ int main(int argc, FAR char *argv[])
       goto errout;
     }
 
-  name[0] = '\0';
   if (argc == 1)
     {
       /* No arguments - show current mode */
diff --git a/system/trace/trace.h b/system/trace/trace.h
index 2f5337a41..bf63d96b2 100644
--- a/system/trace/trace.h
+++ b/system/trace/trace.h
@@ -54,7 +54,7 @@ extern "C"
  *
  ****************************************************************************/
 
-int trace_dump(FAR FILE *out, bool binary);
+int trace_dump(FAR const char *filename, FAR FILE *out, bool binary);
 
 /****************************************************************************
  * Name: trace_dump_clear
diff --git a/system/trace/trace_dump.c b/system/trace/trace_dump.c
index bbb85ea62..2ba22f031 100644
--- a/system/trace/trace_dump.c
+++ b/system/trace/trace_dump.c
@@ -36,6 +36,12 @@
 
 #include "trace.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define TRACE_DUMP_BUFFER_SIZE 1024
+
 /****************************************************************************
  * Name: note_ioctl
  ****************************************************************************/
@@ -67,18 +73,20 @@ static void note_ioctl(int cmd, unsigned long arg)
  *
  ****************************************************************************/
 
-int trace_dump(FAR FILE *out, bool binary)
+int trace_dump(FAR const char *filename, FAR FILE *out, bool binary)
 {
   uint8_t *tracedata = NULL;
+  char path[PATH_MAX];
   int ret;
   int fd;
 
   /* Open note for read */
 
-  fd = open("/dev/note/ram", O_RDONLY);
+  snprintf(path, sizeof(path), "/dev/note/%s", filename);
+  fd = open(path, O_RDONLY);
   if (fd < 0)
     {
-      fprintf(stderr, "trace: cannot open /dev/note/ram\n");
+      fprintf(stderr, "trace: cannot open %s\n", path);
       return ERROR;
     }
 
@@ -95,7 +103,7 @@ int trace_dump(FAR FILE *out, bool binary)
         }
     }
 
-  tracedata = malloc(1024);
+  tracedata = malloc(TRACE_DUMP_BUFFER_SIZE);
   if (tracedata == NULL)
     {
       fprintf(stderr, "trace: cannot allocate memory\n");
@@ -107,8 +115,8 @@ int trace_dump(FAR FILE *out, bool binary)
 
   while (1)
     {
-      ret = read(fd, tracedata, sizeof tracedata);
-      if (ret < 0 || ret > sizeof(tracedata))
+      ret = read(fd, tracedata, TRACE_DUMP_BUFFER_SIZE);
+      if (ret < 0 || ret > TRACE_DUMP_BUFFER_SIZE)
         {
           fprintf(stderr, "trace: read error: %d, errno:%d\n", ret, errno);
           continue;

Reply via email to