Click here to Skip to main content
6,629,377 members and growing! (24,035 online)
Email Password   helpLost your password?
General Programming » Threads, Processes & IPC » Threads     Advanced

Name your threads in the VC debugger thread list

By Patrick Hoffmann

The VC debugger displays a name for every thread. This article describes how to control what VC displays in the thread list.
VC6, VC7, VC7.1, VC8.0Win2K, WinXP, Win2003, Vista, Visual Studio, Dev
Posted:13 Oct 2004
Views:41,512
Bookmarked:39 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
19 votes for this article.
Popularity: 5.09 Rating: 3.98 out of 5
1 vote, 5.3%
1
1 vote, 5.3%
2
2 votes, 10.5%
3
6 votes, 31.6%
4
9 votes, 47.4%
5

Sample Image - Name_threads_in_debugger.png

Introduction

Some days ago, someone asked me if it is possible to rename threads in the VC debugger. Because I worked at a multi threading project myself those days, I was very interested in realizing this idea. Some Google group searches later, I had a solution that is short and easy. Because this could be very helpful for everyone working on applications with many threads, I publish it here.

There isn't much to understand except, that the VC debugger gets the information about a thread's name via the exception #0x406D1388.

I put the necessary call into a simple function. Here is the code:

//

// Usage: SetThreadName (-1, "MainThread");

//

typedef struct tagTHREADNAME_INFO
{
  DWORD dwType; // must be 0x1000

  LPCSTR szName; // pointer to name (in user addr space)

  DWORD dwThreadID; // thread ID (-1=caller thread)

  DWORD dwFlags; // reserved for future use, must be zero

} THREADNAME_INFO;

void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
{
  THREADNAME_INFO info;
  {
    info.dwType = 0x1000;
    info.szName = szThreadName;
    info.dwThreadID = dwThreadID;
    info.dwFlags = 0;
  }
  __try
  {
    RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info );
  }
  __except (EXCEPTION_CONTINUE_EXECUTION)
  {
  }
}

You just have to call SetThreadName() with the thread ID and a name string as parameters.

Have fun with that tiny tool ;)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Patrick Hoffmann


Member

Occupation: Web Developer
Location: Germany Germany

Other popular Threads, Processes & IPC articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh)FirstPrevNext
GeneralMy vote of 2 PinmemberSarath.8:56 5 Mar '09  
GeneralI'm having a "Fifth Element" moment here... PinmemberAndreyT12:56 4 Apr '08  
GeneralNice article PinmemberThatsAlok20:57 25 Jul '07  
Questionhow i can have optional number of threads?? Pinmemberkamelian_2023:08 14 Mar '07  
GeneralHere is a hint Pinmemberndl8:04 19 Apr '06  
QuestionAttaching to Process Pinmemberrobma12:22 3 Nov '05  
AnswerRe: Attaching to Process PinmemberPatrick Hoffmann13:38 3 Nov '05  
GeneralThanks Patrick PinmemberMichael Holm3:04 13 Oct '04  
GeneralRe: Thanks Patrick PinmemberNeville Franks10:55 13 Oct '04  
GeneralWhy repeating the MSDN !? PinmemberJochen Kalmbach1:42 13 Oct '04  
GeneralRe: Why repeating the MSDN !? PinmemberPatrick Hoffmann2:23 13 Oct '04  
GeneralDoes this only work in .NET? Pinmemberaaronp3:31 13 Oct '04  
GeneralRe: Does this only work in .NET? PinmemberJochen Kalmbach4:03 13 Oct '04  
GeneralRe: Does this only work in .NET? PinmemberJochen Kalmbach4:08 13 Oct '04  
GeneralRe: Does this only work in .NET? Pinsussaaronp6:28 13 Oct '04  
GeneralRe: Does this only work in .NET? PinmemberJochen Kalmbach10:26 13 Oct '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Oct 2004
Editor: Smitha Vijayan
Copyright 2004 by Patrick Hoffmann
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project