分享
 
 
 

VC调试技术小技巧(2)

王朝vc·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

#ifndef XTIB_H

#define XTIB_H

// Call SetThreadName(), and then paste this expression into the watch window:

// (char*)(DW(@TIB+0x14))

#pragma pack(1)

typedef struct _EXCEPTION_REGISTRATION_RECORD

{

struct _EXCEPTION_REGISTRATION_RECORD * pNext;

FARPROC pfnHandler;

} EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD;

typedef struct tagXTIB

{

PEXCEPTION_REGISTRATION_RECORD pvExcept; // 00h Head of exception record list

PVOID pvStackUserTop; // 04h Top of user stack

PVOID pvStackUserBase; // 08h Base of user stack

union // 0Ch (NT/Win95 differences)

{

struct // Win95 fields

{

WORD pvTDB; // 0Ch TDB

WORD pvThunkSS; // 0Eh SS selector used for thunking to 16 bits

DWORD unknown1; // 10h

} WIN95;

struct // WinNT fields

{

PVOID SubSystemTib; // 0Ch

ULONG FiberData; // 10h

} WINNT;

} TIB_UNION1;

PVOID pvArbitrary; // 14h Available for application use

struct _tib *ptibSelf; // 18h Linear address of TIB structure

union // 1Ch (NT/Win95 differences)

{

struct // Win95 fields

{

WORD TIBFlags; // 1Ch

WORD Win16MutexCount; // 1Eh

DWORD DebugContext; // 20h

DWORD pCurrentPriority; // 24h

DWORD pvQueue; // 28h Message Queue selector

} WIN95;

struct // WinNT fields

{

DWORD unknown1; // 1Ch

DWORD processID; // 20h

DWORD threadID; // 24h

DWORD unknown2; // 28h

} WINNT;

} TIB_UNION2;

PVOID* pvTLSArray; // 2Ch Thread Local Storage array

union // 30h (NT/Win95 differences)

{

struct // Win95 fields

{

PVOID* pProcess; // 30h Pointer to owning process database

} WIN95;

} TIB_UNION3;

// Internal function to get the TIB

/*----------------------------------------------------------------------

FUNCTION : GetTIB

DESCRIPTION : Returns pointer to TIB for current thread.

PARAMETERS : None.

RETURNS : NULL - A really bad thing

!NULL - Pointer to TIB for current thread

----------------------------------------------------------------------*/

static tagXTIB * GetTIB()

{

tagXTIB * pTib;

__asm

{

MOV EAX , FS:[18h]

MOV pTib , EAX

}

return pTib;

}

/*----------------------------------------------------------------------

FUNCTION : SetThreadName

DESCRIPTION : SetThreadName provides a way to "name" your threads so that you can

see at a glance which thread is active when you are in the debugger.

Calling SetThreadName sets the string pointer parameter into the Thread

Information Block (TIB) pvArbitrary field (offset 0x14). Matt Pietrek

discussed the TIB structure in his May 1996 "Under the Hood" column.

I included Matt's TIB.h as part of this project if you want to see the

rest of the fields in the TIB.

pvArbitrary is an unused spot in the TIB that applications can use

as they wish. SetThreadName does the right thing and checks if the

pvArbitrary is not 0 and will not write the string pointer to avoid

tromping on any other data written there.

To view which thread is active in the Watch window, use

"(char*)(DW(@TIB+0x14))" As you swap threads, you can now tell at a

glance which thread you are in!

PARAMETERS : szName - A pointer to the string which you would like to name the

current thread. You should make the string pointer a

constant name.

RETURNS : TRUE - The thread name was set.

FALSE - Something else overwrote the pvArbitrary field.

----------------------------------------------------------------------*/

static BOOL SetThreadName(LPCTSTR szName)

{

// Grab the TIB.

tagXTIB * pTib = GetTIB();

// If someone has already written to the arbitrary field, I don't

// want to be overwriting it.

if (pTib->pvArbitrary != NULL)

return FALSE;

// Nothing's there. Set the name.

pTib->pvArbitrary = (void*)szName;

return TRUE;

}

/*----------------------------------------------------------------------

FUNCTION : GetThreadName

DESCRIPTION : Returns the string pointer to the name assigned to the

current thread.

PARAMETERS : None.

RETURNS : NULL - No name was assigned.

!NULL - The value at the TIB pvArbitrary offset. Please

note that the pointer could be invalid of if something

other than SetThreadName used the pvArbitrary offset.

----------------------------------------------------------------------*/

static LPCTSTR GetThreadName()

{

// Grab the TIB.

tagXTIB * pTib = GetTIB();

return (LPCTSTR)pTib->pvArbitrary;

}

} XTIB;

#pragma pack()

#endif //XTIB_H

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有