TraceReg

Purpose

Returns the address of memory block containing the processor register values.

Syntax

addr% = TraceReg

value = TraceReg(reg)

TraceReg(reg) = value

addr, value:iexp

reg: a register, one of Eax, Ebx, Ecx, Edx, Ebp, Esp, Esi, Edi, Efl, Eip and the 16 bit register parts Ax, Bx, Cx, Dx, Bp, Sp, Si, Di, Fl, and the 8 bit register parts Al, Bl, Cl, Dl, Ah, Bh, Ch, Dh.

Description

TraceReg returns the address of a memory block containing the value of all processor register in the order edi esi esp ebp ebx edx ecx eax efl eip. To inspect the eax register you would use LPeek(TraceReg + 7*4), because eax is the seventh register in a row.

TraceReg(reg) only returns the value of one register in an appropriate pseudo variable. For instance Dim eax% = TraceReg(Eax).

TraceReg is used a Tron procedure, which is invoked before the next commandwill be executed next. Tron procedurename, specifies a subroutine which will be invoked before execution of every command.

Example

OpenW 1, 0, 0, 600, 500

Local j%

Global i1% = mAlloc(1000), i% = i1%

Tron p

. mov eax, 10

. mov [i%], eax

~1

Troff

~mFree(i1%)

 

Sub p

Local d As New DisAsm

d.ByteFlag = 1

Local j%

SetFont "courier new", 8

Print Trace$

d.Addr = TraceReg(Eip)

For j = 1 To 5

Exit If LPeek(d.Addr) %& 0xffffff == 0xb455ff

Print d

Next

SetFont "Arial", 8, , 1

Print "i ="; i; TraceLnr`Trace$

EdShowLine TraceLnr - 1 : Delay .5

If InStr(Trace$, "[i]") Then

For j = 0 To 7

Print {TraceReg + j * 4};

Next

Print

Print "Eax ="; TraceReg(Eax)

TraceReg(Eax) = 123

EndIf

EndSub

The main program consists of two assembler instructions. The first one moves the value 10 to the register eax, the second moves the contents of eax to the variable i% (the ~1 makes sure, that the last used floating point register is cleared, not relevant here, though.)

The Tron procedure p prints the contents of the variable i% followed by the current line number and source code text of that line. The command EdShowLine shows the normal Tron arrow in front of the actual line. A small delay makes it possible to notice the current line.

Finally, if the source code line contains "[i%]", the value 123 is written as integer into memory, which address is obtained using TraceReg+7*4.
As a complete debugger, Tron needs access to the processor registers. TraceReg returns the address of the memory range, where for the actual processor registers are placed in. With TraceReg+7*4 the seventh register (0,1,2,3,4,5,6,eax ) will be changed. As a result, 123 will placed in eax and thus in i%.

This example has been changed a little compared to the one presented in EdShowLine. In the Tron subroutine a DisAsm object is created and used to display the disassembly of the current line. After selecting a non-proportional font ("Courier New" 8 points) the next program line Trace$ is displayed followed by a maximum of five lines of disassembly. The 'strange' Exit If compares the next assembler instruction to 'call dpt -76[ebp]'. This 3 byte instruction is generated between each program line when $Step is on. As a result, only the assembler code for the next to execute line is showed. The irrelevant code is ignored.

Remarks

In a stand-alone program (EXE) the Tron command is ignored. TraceLnr, ProcLnr(p) and ProcLineCnt(p) are 0, Trace$ and SrcCode(%) are "".

See Also

Tron, Debug, Trace, TraceLnr, TraceReg, SrcCode$, ProcLnr, ProcLineCnt, $StepOff

{Created by Sjouke Hamstra; Last updated: 25/10/2014 by James Gaite}