Skip to content

Commit f953d5b

Browse files
committed
recorder: Add commands to control the recorder
Add `FlightRecorderConfigure` command to configure recorder tracing from within DB48x. Add `FlightRecorderDump` and `FlightRecorderDumpSome` to to a full or partial dump of the flight recorder. Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
1 parent 96c91d8 commit f953d5b

12 files changed

Lines changed: 104 additions & 6 deletions

File tree

doc/8-menus-tree-dm32.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ Access: 🟦 X (1); [ProgramMenu](#programmenu) 🟦 F2
235235

236236
| F1 | F2 | F3 | F4 | F5 | F6 |
237237
|:--:|:--:|:--:|:--:|:--:|:--:|
238-
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | | | |
238+
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | Record | WSLog | DumpSome |
239239
| [Halt](#halt) | [Step↑](#stepout) | DoErr | ErrMsg | ErrNum | ClrErr |
240240
| [Debug](#debug) | [Step](#step) | [Over](#over) | [Steps](#multiplesteps) | [Continue](#continue) | [Kill](#kill) |
241241

doc/8-menus-tree-dm42.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ Access: 🟦 X (1); [ProgramMenu](#programmenu) 🟦 F2
235235

236236
| F1 | F2 | F3 | F4 | F5 | F6 |
237237
|:--:|:--:|:--:|:--:|:--:|:--:|
238-
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | | | |
238+
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | Record | WSLog | DumpSome |
239239
| [Halt](#halt) | [Step↑](#stepout) | DoErr | ErrMsg | ErrNum | ClrErr |
240240
| [Debug](#debug) | [Step](#step) | [Over](#over) | [Steps](#multiplesteps) | [Continue](#continue) | [Kill](#kill) |
241241

help/db48x.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22288,7 +22288,7 @@ Access: 🟦 X (1); [ProgramMenu](#programmenu) 🟦 F2
2228822288

2228922289
| F1 | F2 | F3 | F4 | F5 | F6 |
2229022290
|:--:|:--:|:--:|:--:|:--:|:--:|
22291-
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | | | |
22291+
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | Record | WSLog | DumpSome |
2229222292
| [Halt](#halt) | [Step↑](#stepout) | DoErr | ErrMsg | ErrNum | ClrErr |
2229322293
| [Debug](#debug) | [Step](#step) | [Over](#over) | [Steps](#multiplesteps) | [Continue](#continue) | [Kill](#kill) |
2229422294

help/db50x.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22305,7 +22305,7 @@ Access: 🟦 X (1); [ProgramMenu](#programmenu) 🟦 F2
2230522305

2230622306
| F1 | F2 | F3 | F4 | F5 | F6 |
2230722307
|:--:|:--:|:--:|:--:|:--:|:--:|
22308-
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | | | |
22308+
| [Run](#run) | [ErrDbg](#debugonerror) | \[[Prog](#programmenu)\] | Record | WSLog | DumpSome |
2230922309
| [Halt](#halt) | [Step↑](#stepout) | DoErr | ErrMsg | ErrNum | ClrErr |
2231022310
| [Debug](#debug) | [Step](#step) | [Over](#over) | [Steps](#multiplesteps) | [Continue](#continue) | [Kill](#kill) |
2231122311

src/ids.tbl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,11 @@ CMD(MultipleSteps)
852852
CMD(Continue) ALIAS(Continue, "cont")
853853
CMD(Kill)
854854

855+
// DB48x debugging
856+
CMD(FlightRecorderConfigure)
857+
CMD(FlightRecorderDump) ALIAS(FlightRecorderDump, "WSLog")
858+
CMD(FlightRecorderDumpSome)
859+
855860
// Input and prompting
856861
CMD(Input)
857862
CMD(Prompt)

src/menu.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,10 @@ MENU(DebugMenu,
980980

981981
"Run", ID_Run,
982982
"ErrDbg", ID_DebugOnError,
983-
"Prog", ID_ProgramMenu);
983+
"Prog", ID_ProgramMenu,
984+
"Record", ID_FlightRecorderConfigure,
985+
"WSLog", ID_FlightRecorderDump,
986+
"DumpSome", ID_FlightRecorderDumpSome);
984987

985988

986989
MENU(TestsMenu,

src/program.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,66 @@ COMMAND_BODY(RuntimeStatistics)
593593

594594
return ERROR;
595595
}
596+
597+
598+
599+
// ============================================================================
600+
//
601+
// Flight recorder control
602+
//
603+
// ============================================================================
604+
605+
static bool run_cstring_command(int (*fn)(cstring))
606+
// ----------------------------------------------------------------------------
607+
// Shared code to run a C function taking a null-terminated string as input
608+
// ----------------------------------------------------------------------------
609+
{
610+
if (object_p config = object::strip(rt.top()))
611+
{
612+
if (text_p wanted = config->as<text>())
613+
{
614+
int result = fn(wanted->null_terminated_value());
615+
integer_p rc = integer::make(result);
616+
return rc && rt.top(rc);
617+
}
618+
rt.type_error();
619+
}
620+
return false;
621+
}
622+
623+
624+
static inline bool run_cstring_command(uint (*fn)(cstring))
625+
// ----------------------------------------------------------------------------
626+
// We don't really care if function return unsigned
627+
// ----------------------------------------------------------------------------
628+
{
629+
return run_cstring_command((int (*)(cstring)) fn);
630+
}
631+
632+
633+
COMMAND_BODY(FlightRecorderConfigure)
634+
// ----------------------------------------------------------------------------
635+
// Configure specific traces for the flight recorder
636+
// ----------------------------------------------------------------------------
637+
{
638+
return run_cstring_command(recorder_trace_set) ? OK : ERROR;
639+
}
640+
641+
642+
COMMAND_BODY(FlightRecorderDump)
643+
// ----------------------------------------------------------------------------
644+
// Cause a flight recorder dump
645+
// ----------------------------------------------------------------------------
646+
{
647+
recorder_dump();
648+
return OK;
649+
}
650+
651+
652+
COMMAND_BODY(FlightRecorderDumpSome)
653+
// ----------------------------------------------------------------------------
654+
// Cause a partial flight recorder dump
655+
// ----------------------------------------------------------------------------
656+
{
657+
return run_cstring_command(recorder_dump_for) ? OK : ERROR;
658+
}

src/program.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,8 @@ COMMAND_DECLARE(Continue,-1);
114114
COMMAND_DECLARE(Kill,-1);
115115
COMMAND_DECLARE(RuntimeStatistics,0);
116116

117+
COMMAND_DECLARE(FlightRecorderConfigure, 1);
118+
COMMAND_DECLARE(FlightRecorderDump, 0);
119+
COMMAND_DECLARE(FlightRecorderDumpSome, 1);
120+
117121
#endif // PROGRAM_H

src/recorder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ void assertion_failed(const char *);
5555
#define RECORDER_TWEAK(Name) 0
5656
#define RECORD(rec, fmt, ...) do { recorder_ignore(__VA_ARGS__); } while(0)
5757
#define record(...) RECORD(__VA_ARGS__)
58+
inline unsigned recorder_dump() { return 0; }
59+
inline unsigned recorder_dump_for(const char *set) { return 0; }
60+
inline int recorder_trace_set(const char *set) { return 0; }
5861

5962
// This is just to avoid warnings about unused parameters
6063
inline void recorder_ignore() {}

src/text.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ size_t text::utf8_characters() const
178178
}
179179

180180

181+
cstring text::null_terminated_value() const
182+
// ----------------------------------------------------------------------------
183+
// Return a null-terminated string for standard C functions (don't abuse it)
184+
// ----------------------------------------------------------------------------
185+
{
186+
size_t sz;
187+
utf8 txt = value(&sz);
188+
if (!txt[sz - 1])
189+
return cstring(txt);
190+
191+
char zero = 0;
192+
text_p padded = text_g(this) + text_g(text::make(&zero, 1));
193+
if (!padded)
194+
return "";
195+
return cstring(padded->value(nullptr));
196+
}
197+
198+
181199
object_p text::compile() const
182200
// ----------------------------------------------------------------------------
183201
// Compile and run the text as if on the command line

0 commit comments

Comments
 (0)