Você está na página 1de 19

CnPack

http://www.cnpack.org

CnDebugger

Blue++(zy_hon@hotmail.com )
(liuxiao@cnpack.org)
CnPack

V0.1.0.7
2006.09.05
2008.05.01

1) CnDebugger

CnDebugger CnPack Windows Delphi/C++Builder

CnDebug
CnDebugger
CnDebugger
CnDebugger

Msg
Level
LevelLevel Level 2
2 Level 2 Level 0 3
3 Level
MsgType
Tag 8


CnDebugger CnDebug.pas initialization finalization

(C)Copyright 2001-2011 CnPack 1 19


CnPack
http://www.cnpack.org

2) CnDebug.pas

CnDebug.pas

USE_JCL CnDebug.pas
JCL JCL JCL CnDebug.pas
JCL Include TD32 debug Info
MapFile
CnDebug.pas RTTI
SUPPORT_EVALUATE CnPack
CnPropSheetFrm.pas

3) C++Builder CnDebug.pas

C++Builder CnDebug.pas CnDebug.pas


#include CnDebug.hpp CnDebugger()-
>TraceMsg(AMsg);hpp

4) CnDebug.pas

CnDebug.pas CnDebugViewer
CnDebugViewer CnDebug.pas CnDebugViewer

CnDebugViewer CnWizards CnDebugger

2 CnDebugger

1) CnDebugger

CnDebugger
LogMsg LogMsgWarning LogColor LogStrings
LogEnter/TraceEnterLogLeave/TraceLeave
RTTI
Exception
implementation uses CnDebug Project Options
Conditional Defines DEBUG CnDebugger
Log/Trace
CnDebugger Log Trace
Log DEBUG Trace
NDEBUG

Log := IFNDEF NDEBUG and IFDEF DEBUG


Trace := IFNDEF NDEBUG

(C)Copyright 2001-2011 CnPack 2 19


CnPack
http://www.cnpack.org

Log DEBUG
Trace
NDEBUG
CnDebug.pas RTTI
SUPPORT_EVALUATESUPPORT_EVALUATE NDEBUG
UNDEF
CnDebug.pas
DUMP_TO_FILE
CnDebugDump.cddDUMP_TO_FILE NDEBUG
UNDEF
DEBUG Project Options

2)

CnDebug.pas

3)

property Channel: TCnDebugChannel;


TCnDebugChannel Channel
TCnDebugChannel CnDebug.pas Channel

property Filter: TCnDebugFilter;


TcnDebugFilter

property Active: Boolean;


property ExceptTracking: Boolean;


Active True

property AutoStart: Boolean;


Debug Viewer CnDebugger
Debug Viewer CnDebugViewer.exe

property DumpToFile: Boolean;


DUMP_TO_FILE

property DumpFileName: string;

(C)Copyright 2001-2011 CnPack 3 19


CnPack
http://www.cnpack.org

DumpToFile True CnDebugDump.cdd

property UseAppend: Boolean;


UseAppend True
False

property MessageCount: Integer;


property PostedMessageCount: Integer;


Channel

property DiscardedMessageCount: Integer;


MessageCount PostedMessageCount

4)

procedure StartDebugViewer;
Debug Viewer CnDebugViewer.exe

procedure StartTimeMark(const ATag: Integer; const AMsg: string = '');


CPU
StopTimeMark

1. const ATag: Integer;
2. const AMsg: string;

procedure StopTimeMark(const ATag: Integer; const AMsg: string = '');




1. const ATag: Integer; StartTimeMark
2. const AMsg: string;

procedure LogMsg(const AMsg: string);




1. const AMsg: string;

procedure LogMsgWithTag(const AMsg: string; const ATag: string);


(C)Copyright 2001-2011 CnPack 4 19


CnPack
http://www.cnpack.org


1. const AMsg: string;
2. const ATag: string;

procedure LogMsgWithLevel(const AMsg: string; ALevel: Integer);




1. const AMsg: string;
2. ALevel: Integer;

procedure LogMsgWithType(const AMsg: string; Atype: TCnMsgType);




1. const AMsg: string;
2. Atype: TCnMsgType;

procedure LogMsgWithTagLevel(const AMsg: string; const ATag: string;


ALevel: Integer);


1. const AMsg: string;
2. const ATag: string;
3. ALevel: Integer;

procedure LogMsgWithLevelType(const AMsg: string; ALevel: Integer;


AType: TCnMsgType);


1. const AMsg: string;
2. ALevel: Integer;
3. AType: TcnMsgType;

procedure LogMsgWithTypeTag(const AMsg: string; AType: TCnMsgType; const


ATag: string);


1. const AMsg: string;
2. AType: TcnMsgType;
3. const ATag: string;

procedure LogFmt(const AFormat: string; Args: array of const);




1. const AFormat: string;

(C)Copyright 2001-2011 CnPack 5 19


CnPack
http://www.cnpack.org

2. Args: array of const;

procedure LogFmtWithTag(const AFormat: string; Args: array of const;


const ATag: string);


1. const AFormat: string;
2. Args: array of const;
3. const ATag: string;

procedure LogFmtWithLevel(const AFormat: string; Args: array of const;


ALevel: Integer);


1. const AFormat: string;
2. Args: array of const;
3. ALevel: Integer;

procedure LogFmtWithType(const AFormat: string; Args: array of const;


AType: TCnMsgType);


1. const AFormat: string;
2. Args: array of const;
3. AType: TCnMsgType;

procedure LogFull(const AMsg: string; const ATag: string; ALevel:


Integer; AType: TCnMsgType; CPUPeriod: Int64 = 0);


1. const AMsg: string;
2. const ATag: string;
3. ALevel: Integer;
4. AType: TCnMsgType;
5. CPUPeriod: Int64; CPU 0

procedure LogSeparator;


procedure LogEnter(const AProcName: string; const ATag: string = '');



(C)Copyright 2001-2011 CnPack 6 19


CnPack
http://www.cnpack.org

1. const AProcName: string;


2. const ATag: string;

procedure LogLeave(const AProcName: string; const ATag: string = '');




1. const AProcName: string;
2. const ATag: string;

procedure LogMsgWarning(const AMsg: string);




1. const AMsg: string;

procedure LogMsgError(const AMsg: string);




1. const AMsg: string;

procedure LogErrorFmt(const AFormat: string; Args: array of const);




1. const AFormat: string;
2. Args: array of const;

procedure LogLastError;


procedure LogAssigned(Value: Pointer; const AMsg: string = '');


( nil)

1. Value: Pointer;
2. const AMsg: string;

procedure LogBoolean(Value: Boolean; const AMsg: string = '');




1. Value: Boolean;
2. const AMsg: string;

procedure LogColor(Color: TColor; const AMsg: string = '');


( Color )

(C)Copyright 2001-2011 CnPack 7 19


CnPack
http://www.cnpack.org


1. Color: TColor;
2. const AMsg: string;

procedure LogFloat(Value: Extended; const AMsg: string = '');




1. Value: Extended;
2. const AMsg: string;

procedure LogInteger(Value: Integer; const AMsg: string = '');




1. Value: Integer;
2. const AMsg: string;

procedure LogChar(Value: Char; const AMsg: string = '');


ASCII

1. Value: Char;
2. const AMsg: string;

procedure LogDateTime(Value: TDateTime; const AMsg: string = '' );


yyyy-mm-dd hh:nn:ss.zzz

1. Value: TDateTime;
2. const AMsg: string;

procedure LogDateTimeFmt(Value: TDateTime; const AFmt: string; const


AMsg: string = '' );


1. Value: TDateTime;
2. const AFmt: string;
3. const AMsg: string;

procedure LogPointer(Value: Pointer; const AMsg: string = '');


Pointer

1. Value: Pointer;
2. const AMsg: string;

procedure LogPoint(Point: TPoint; const AMsg: string = '');


TPoint

(C)Copyright 2001-2011 CnPack 8 19


CnPack
http://www.cnpack.org


1. Point: TPoint; TPoint
2. const AMsg: string;

procedure LogRect(Rect: TRect; const AMsg: string = '');


TRect

1. Rect: TRect; TRect
2. const AMsg: string;

procedure LogStrings(Strings: TStrings; const AMsg: string = '');


TStrings

1. Strings: TStrings; TStrings
2. const AMsg: string;

procedure LogMemDump(AMem: Pointer; Size: Integer);




1. AMem: Pointer; Pointer
2. Size: Integer;

procedure LogVirtualKey(AKey: Word);




1. AKey: Word;

procedure LogVirtualKeyWithTag(AKey: Word; const ATag: string);




1. AKey: Word;
2. const ATag: string;

procedure LogObject(AObject: TObject);




1. AObject: TObject;

procedure LogObjectWithTag(AObject: TObject; const ATag: string);




1. AObject: Tobject;
2. const ATag: string;

(C)Copyright 2001-2011 CnPack 9 19


CnPack
http://www.cnpack.org

procedure LogCollection(ACollection: TCollection);


TCollection

1. ACollection: TCollection; TCollection

procedure LogCollectionWithTag(ACollection: TCollection; const ATag:


string);
TCollection

1. ACollection: TCollection; TCollection
2. const ATag: string;

procedure LogComponent(AComponent: TComponent);




1. AComponent: TComponent;

procedure LogComponentWithTag(AComponent: TComponent; const ATag:


string);


1. AComponent: TComponent;
2. const ATag: string;

procedure TraceMsg(const AMsg: string);




1. const AMsg: string;

procedure TraceMsgWithTag(const AMsg: string; const ATag: string);




1. const AMsg: string;
2. const ATag: string;

procedure TraceMsgWithLevel(const AMsg: string; ALevel: Integer);




1. const AMsg: string;
2. ALevel: Integer;

procedure TraceMsgWithType(const AMsg: string; Atype: TCnMsgType);



(C)Copyright 2001-2011 CnPack 10 19


CnPack
http://www.cnpack.org

1. const AMsg: string;


2. Atype: TCnMsgType;

procedure TraceMsgWithTagLevel(const AMsg: string; const ATag: string;


ALevel: Integer);


1. const AMsg: string;
2. const ATag: string;
3. ALevel: Integer;

procedure TraceMsgWithLevelType(const AMsg: string; ALevel: Integer;


AType: TCnMsgType);


1const AMsg: string;
2ALevel: Integer;
3AType: TcnMsgType;

procedure TraceMsgWithTypeTag(const AMsg: string; AType: TCnMsgType;


const ATag: string);


1const AMsg: string;
2AType: TcnMsgType;
3const ATag: string;

procedure TraceFmt(const AFormat: string; Args: array of const);




1. const AFormat: string;
2. args: array of const;

procedure TraceFmtWithTag(const AFormat: string; Args: array of const;


const ATag: string);


1. const AFormat: string;
2. Args: array of const;
3. const ATag: string;

procedure TraceFmtWithLevel(const AFormat: string; Args: array of const;


ALevel: Integer);

(C)Copyright 2001-2011 CnPack 11 19


CnPack
http://www.cnpack.org


1. const AFormat: string;
2. Args: array of const;
3. ALevel: Integer;

procedure TraceFmtWithType(const AFormat: string; Args: array of const;


AType: TCnMsgType);


1. const AFormat: string;
2. Args: array of const;
3. AType: TCnMsgType;

procedure TraceFull(const AMsg: string; const ATag: string; ALevel:


Integer; AType: TCnMsgType; CPUPeriod: Int64 = 0);


1. const AMsg: string;
2. const ATag: string;
3. ALevel: Integer;
4. AType: TCnMsgType;
5. CPUPeriod: Int64; CPU 0

procedure TraceSeparator;


procedure TraceEnter(const AProcName: string; const ATag: string = '');




1. const AProcName: string;
2. const ATag: string;

procedure TraceLeave(const AProcName: string; const ATag: string = '');




1. const AProcName: string;
2. const ATag: string;

procedure TraceMsgWarning(const AMsg: string);




1. const AMsg: string;

(C)Copyright 2001-2011 CnPack 12 19


CnPack
http://www.cnpack.org

procedure TraceMsgError(const AMsg: string);




2. const AMsg: string;

procedure TraceErrorFmt(const AFormat: string; Args: array of const);




1. const AFormat: string;
2. Args: array of const;

procedure TraceLastError;


procedure TraceAssigned(Value: Pointer; const AMsg: string = '');


( nil)

1. Value: Pointer;
2. const AMsg: string;

procedure TraceBoolean(Value: Boolean; const AMsg: string = '');




1. Value: Boolean;
2. const AMsg: string;

procedure TraceColor(Color: TColor; const AMsg: string = '');


( Color )

1. Color: TColor;
2. const AMsg: string;

procedure TraceFloat(Value: Extended; const AMsg: string = '');




1. Value: Extended;
2. const AMsg: string;

procedure TraceInteger(Value: Integer; const AMsg: string = '');



(C)Copyright 2001-2011 CnPack 13 19


CnPack
http://www.cnpack.org

1. Value: Integer;
2. const AMsg: string;

procedure TraceChar(Value: Char; const AMsg: string = '');


ASCII

1. Value: Char;
2. const AMsg: string;

procedure TraceDateTime(Value: TDateTime; const AMsg: string = '' );


yyyy-mm-dd hh:nn:ss.zzz

1. Value: TDateTime;
2. const AMsg: string;

procedure TraceDateTimeFmt(Value: TDateTime; const AFmt: string; const


AMsg: string = '' );


1. Value: TDateTime;
2. const AFmt: string;
3. const AMsg: string;

procedure TracePointer(Value: Pointer; const AMsg: string = '');


Pointer

1. Value: Pointer;
2. const AMsg: string;

procedure TracePoint(Point: TPoint; const AMsg: string = '');


TPoint

1. Point: TPoint; TPoint
2. const AMsg: string;

procedure TraceRect(Rect: TRect; const AMsg: string = '');


TRect

1. Rect: TRect; TRect
2. const AMsg: string;

procedure TraceStrings(Strings: TStrings; const AMsg: string = '');


TStrings

(C)Copyright 2001-2011 CnPack 14 19


CnPack
http://www.cnpack.org

1. Strings: TStrings; TStrings


2. const AMsg: string;

procedure TraceMemDump(AMem: Pointer; Size: Integer);




1. AMem: Pointer; Pointer
2. Size: Integer;

procedure TraceVirtualKey(AKey: Word);




1. AKey: Word;

procedure TraceVirtualKeyWithTag(AKey: Word; const ATag: string);




1. AKey: Word;
2. const ATag: string;

procedure TraceObject(AObject: TObject);




1. AObject: TObject;

procedure TraceObjectWithTag(AObject: TObject; const ATag: string);




1 AObject: TObject;
2 const ATag: string;

procedure TraceCollection(ACollection: TCollection);


TCollection

1. ACollection: TCollection; TCollection

procedure TraceCollectionWithTag(ACollection: TCollection; const ATag:


string);
TCollection

1. ACollection: TCollection; TCollection
2. const ATag: string;

procedure TraceComponent(AComponent: TComponent);

(C)Copyright 2001-2011 CnPack 15 19


CnPack
http://www.cnpack.org



1. AComponent: TComponent;

procedure TraceComponentWithTag(AComponent: TComponent; const ATag:


string);


1. AComponent: TComponent;
2. const ATag: string;

procedure AddFilterExceptClass(E: ExceptClass); overload;




1. E: ExceptClass;

procedure RemoveFilterExceptClass(E: ExceptClass); overload;




1. E: ExceptClass;

procedure AddFilterExceptClass(const EClassName: string); overload;




1. const AMsg: string;

procedure RemoveFilterExceptClass(const EClassName: string); overload;




1. const EClassName: string;

procedure EvaluateObject(AObject: TObject); overload;


Object Inspector RTTI
SUPPORT_EVALUATE

1. AObject: TObject;

procedure EvaluateObject(APointer: Pointer); overload;


Object Inspector RTTI
SUPPORT_EVALUATE

1. APointer: Pointer;

(C)Copyright 2001-2011 CnPack 16 19


CnPack
http://www.cnpack.org

3 CnDebug.pas Channel

CnDebug.pas TCnDebugChannel
TCnDebugChannel CnDebugger Viewer
CnDebug.pas TCnMapFileChannel
CnDebugViewer
TCnMapFileChannel CnDebugViewer

CnDebug.pas

var
CnDebugChannelClass: TCnDebugChannelClass = TCnMapFileChannel;

CnDebugger Channel TCnMapFileChannel


CnDebugViewer
TCnDebugChannel
TMyChannel CnDebug.pas initialization
Channel

CnDebugChannelClass := TMyChannel;

TCnDebugChannel

TCnDebugChannel

TCnDebugChannel = class(TObject)
{* Channel }
private
FAutoFlush: Boolean;
FActive: Boolean;
procedure SetAutoFlush(const Value: Boolean);
protected
procedure SetActive(const Value: Boolean); virtual;
// Active
function CheckReady: Boolean; virtual;
//
procedure UpdateFlush; virtual;
// AutoFlush
public
constructor Create(IsAutoFlush: Boolean = True); virtual;
//
procedure StartDebugViewer; virtual;
// Debug Viewer

(C)Copyright 2001-2011 CnPack 17 19


CnPack
http://www.cnpack.org

function CheckFilterChanged: Boolean; virtual;


//
procedure RefreshFilter(Filter: TCnDebugFilter); virtual;
//
procedure SendContent(var MsgDesc; Size: Integer); virtual;
//
property Active: Boolean read FActive write SetActive;
//
property AutoFlush: Boolean read FAutoFlush write SetAutoFlush;
//
end;

TCnDebugChannel SendContent CnDebugger


MsgDesc TCnMsgDesc

{$NODEFINE TCnMsgAnnex}
TCnMsgAnnex = packed record
{* }
Level: Integer; // Level

Indent: Integer; // Enter


Leave
ProcessId: DWORD; // ID
ThreadId: DWORD; // ID
Tag: array[0..CnMaxTagLength - 1] of Char; // Tag

MsgType: DWORD; //
MsgCPInterval: DWORD; // CPU
TimeStampType: DWORD; //
case Integer of
1: (MsgDateTime: TDateTime); //
DateTime
2: (MsgTickCount: DWORD); //
TickCount
3: (MsgCPUPeriod: Int64); // CPU

end;

{$NODEFINE TCnMsgDesc}
{$NODEFINE PCnMsgDesc}
TCnMsgDesc = packed record
{* }
Length: Integer; //
Annex: TCnMsgAnnex; //

(C)Copyright 2001-2011 CnPack 18 19


CnPack
http://www.cnpack.org

Msg: array[0..CnMaxMsgLength - 1] of Char; //


end;

CnDebug
CnDebugViewer
CnDebugger protected InternalOutputMsg
Channel SendContent
CnDebug.pas

(C)Copyright 2001-2011 CnPack 19 19

Você também pode gostar