Merge branch 'feature/tracer-optimizations' into feature/USB

This commit is contained in:
t3hn3rd committed 2026-03-01 21:26:56 +00:00
commit 2fa77d8295
2 files changed
+51 -33

No files matched your search

+9 -2
View File
@@ -581,12 +581,13 @@ begin
syslog.writestring(' EIP: '); syslog.writehex(IntSpec^.EIP); syslog.writestring(' CS: '); syslog.writehex(IntSpec^.CS); syslog.writestring(' EFLAGS: '); syslog.writehexln(IntSpec^.EFLAGS); syslog.writestring(' EIP: '); syslog.writehex(IntSpec^.EIP); syslog.writestring(' CS: '); syslog.writehex(IntSpec^.CS); syslog.writestring(' EFLAGS: '); syslog.writehexln(IntSpec^.EFLAGS);
syslog.writestringln(' '); syslog.writestringln(' ');
end; end;
syslog.writestring('Call Stack: '); tracer.freeze;
syslog.writestring('Call Stack: ');
trace:= tracer.get_last_trace; trace:= tracer.get_last_trace;
if trace <> nil then begin if trace <> nil then begin
syslog.writestring('[-0] '); syslog.writestring('[-0] ');
syslog.writestringln(trace); syslog.writestringln(trace);
for i:=1 to tracer.get_trace_count-7 do begin for i:=1 to tracer.get_trace_count-1 do begin
trace:= tracer.get_trace_N(i); trace:= tracer.get_trace_N(i);
if trace <> nil then begin if trace <> nil then begin
syslog.writestring(' ['); syslog.writestring(' [');
@@ -594,6 +595,12 @@ begin
syslog.writeint(i); syslog.writeint(i);
syslog.writestring('] '); syslog.writestring('] ');
syslog.writestringln(trace); syslog.writestringln(trace);
end else begin
syslog.writestring(' [');
syslog.writestring('-');
syslog.writeint(i);
syslog.writestring('] ');
syslog.writestringln('?????????');
end; end;
end; end;
end else begin end else begin
+42 -31
View File
@@ -13,8 +13,12 @@
// limitations under the License. // limitations under the License.
{ {
Tracer - Trace stack for debugging method calls. Tracer - Ring buffer trace log for debugging method calls.
IMPORTANT: push_trace MUST only be called with pointers to
static/persistent data (e.g. string literals). The pointer is
stored directly - no copy is made.
@author(Kieron Morris <[email protected]>) @author(Kieron Morris <[email protected]>)
} }
unit tracer; unit tracer;
@@ -28,19 +32,12 @@ function get_last_trace : pchar;
procedure freeze; procedure freeze;
function get_trace_count : uint32; function get_trace_count : uint32;
function get_trace_N(idx : uint32) : pchar; function get_trace_N(idx : uint32) : pchar;
procedure print_traces;
implementation implementation
uses uses
lmemorymanager, util, strings, serial, stdio; util, strings, stdio, syslog;
type
PTracerEntry = ^TTracerEntry;
TTracerEntry = record
Next : PTracerEntry;
Data : pchar;
Previous : PTracerEntry;
end;
const const
MAX_TRACE = 40; MAX_TRACE = 40;
@@ -48,16 +45,12 @@ const
var var
t_ready : Boolean; t_ready : Boolean;
Locked : Boolean; Locked : Boolean;
head : uint32;
Traces : Array[0..MAX_TRACE-1] of PChar; Traces : Array[0..MAX_TRACE-1] of PChar;
c_lock : Boolean = false;
var
head : PTracerEntry;
tail : PTracerEntry;
procedure terminal_command_tracer(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf); procedure terminal_command_tracer(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
var var
p1, p2 : PChar; p1 : PChar;
count : uint32; count : uint32;
i : uint32; i : uint32;
t : PChar; t : PChar;
@@ -113,22 +106,15 @@ begin
end; end;
procedure push_trace(t_name : pchar); procedure push_trace(t_name : pchar);
var
i : uint32;
begin begin
if TRACER_ENABLE then begin if TRACER_ENABLE then begin
if t_ready then begin if t_ready then begin
if not Locked then begin if not Locked then begin
if not c_lock then begin Locked:= true;
Locked:= true; head:= head + 1;
if Traces[MAX_TRACE-1] <> nil then kfree(void(Traces[MAX_TRACE-1])); if head >= MAX_TRACE then head:= 0;
for i:=MAX_TRACE-1 downto 1 do begin Traces[head]:= t_name;
Traces[i]:= Traces[i-1]; Locked:= false;
end;
Traces[0]:= StringCopy(t_name);
Locked:= false;
end;
end; end;
end; end;
end; end;
@@ -141,7 +127,7 @@ end;
function get_last_trace : pchar; function get_last_trace : pchar;
begin begin
get_last_trace:= Traces[0]; get_last_trace:= Traces[head];
end; end;
procedure init; procedure init;
@@ -151,8 +137,10 @@ var
begin begin
if TRACER_ENABLE then begin if TRACER_ENABLE then begin
for i:=0 to MAX_TRACE-1 do begin for i:=0 to MAX_TRACE-1 do begin
traces[i]:= nil; Traces[i]:= nil;
end; end;
Locked:= false;
head:= MAX_TRACE - 1;
t_ready:= true; t_ready:= true;
push_trace('kmain'); push_trace('kmain');
end; end;
@@ -166,11 +154,34 @@ begin
end; end;
end; end;
procedure print_traces;
var
i : uint32;
begin
for i:=0 to MAX_TRACE-1 do begin
syslog.log('TRACER', '[');
syslog.writeint(i);
syslog.writestring('] ');
if Traces[i] <> nil then begin
syslog.writestringln(Traces[i]);
end else begin
syslog.writestringln('?????????');
end;
end;
end;
function get_trace_N(idx : uint32) : pchar; function get_trace_N(idx : uint32) : pchar;
var
slot : uint32;
begin begin
if idx > MAX_TRACE-1 then exit; if idx > MAX_TRACE-1 then exit;
if TRACER_ENABLE then begin if TRACER_ENABLE then begin
get_trace_N:= traces[idx]; if head >= idx then
slot:= head - idx
else
slot:= MAX_TRACE - (idx - head);
get_trace_N:= Traces[slot];
end; end;
end; end;