feature: Tracer O(1) ring buffer refactor
- Replaced O(n) shift loop + StringCopy/kalloc/kfree with O(1) ring buffer storing PChar pointers directly (zero allocation). - Eliminated mod operator (causes int64 promotion + broken RTL helpers on i386 bare-metal); uses pure uint32 branch arithmetic. - Removed dead code: PTracerEntry/TTracerEntry linked list types, head/tail PTracerEntry vars, c_lock boolean - Dropped lmemorymanager and serial from uses clause - pop_trace remains as no-op stub for ABI compat - get_trace_N uses underflow-safe index: if head >= idx then head - idx else MAX_TRACE - (idx - head) - Added print_traces debug helper
This commit is contained in:
1 parent
afdc83eaf6
commit
f53afc1d2d
2 files changed
+48
-30
No files matched your search
@@ -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;
|
||||||
|
tracer.freeze;
|
||||||
syslog.writestring('Call Stack: ');
|
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
|
||||||
|
|||||||
+40
-29
@@ -13,7 +13,11 @@
|
|||||||
// 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]>)
|
||||||
}
|
}
|
||||||
@@ -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,25 +106,18 @@ 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;
|
||||||
if Traces[MAX_TRACE-1] <> nil then kfree(void(Traces[MAX_TRACE-1]));
|
head:= head + 1;
|
||||||
for i:=MAX_TRACE-1 downto 1 do begin
|
if head >= MAX_TRACE then head:= 0;
|
||||||
Traces[i]:= Traces[i-1];
|
Traces[head]:= t_name;
|
||||||
end;
|
|
||||||
Traces[0]:= StringCopy(t_name);
|
|
||||||
Locked:= false;
|
Locked:= false;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure pop_trace;
|
procedure pop_trace;
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user