Click here to Skip to main content
Click here to Skip to main content

Name your threads in the VC debugger thread list

By , 12 Oct 2004
 

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
Web Developer
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberSarath.5 Mar '09 - 7:56 
GeneralI'm having a "Fifth Element" moment here...memberAndreyT4 Apr '08 - 11:56 
GeneralNice articlememberThatsAlok25 Jul '07 - 19:57 
Questionhow i can have optional number of threads??memberkamelian_2014 Mar '07 - 22:08 
GeneralHere is a hintmemberndl19 Apr '06 - 7:04 
QuestionAttaching to Processmemberrobma3 Nov '05 - 11:22 
AnswerRe: Attaching to ProcessmemberPatrick Hoffmann3 Nov '05 - 12:38 
GeneralThanks PatrickmemberMichael Holm13 Oct '04 - 2:04 
GeneralRe: Thanks PatrickmemberNeville Franks13 Oct '04 - 9:55 
QuestionWhy repeating the MSDN !?memberJochen Kalmbach13 Oct '04 - 0:42 
AnswerRe: Why repeating the MSDN !?memberPatrick Hoffmann13 Oct '04 - 1:23 
AnswerDoes this only work in .NET?memberaaronp13 Oct '04 - 2:31 
GeneralRe: Does this only work in .NET?memberJochen Kalmbach13 Oct '04 - 3:03 
GeneralRe: Does this only work in .NET?memberJochen Kalmbach13 Oct '04 - 3:08 
GeneralRe: Does this only work in .NET?sussaaronp13 Oct '04 - 5:28 
GeneralRe: Does this only work in .NET?memberJochen Kalmbach13 Oct '04 - 9:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 13 Oct 2004
Article Copyright 2004 by Patrick Hoffmann
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid