Monday, September 10, 2007

Visual Studio 2005 tips & tricks

Here are some tips and trick for Microsoft Visual Studio 2005 (mostly Visual C++ ones).

 

1. Open files in Visual Studio


You can open files from Windows Explorer (or Total Commander, or any similar application) in existing instance of MSVS by specifying shell command for file type:
"...\Microsoft Visual Studio 8\Common7\IDE\devenv.exe" /edit "%1"


 

2. How to Not Step Into Functions using the debugger (article)


Here is my configuration with comments:

Default configuration of MSVC8:

"Security check function"="__security_check_cookie"
"Rpcrt4.dll functions that hinder RPC StepInto"="_ObjectStublessClient.*"
"Rpcrt4.dll function that hinders RPC StepOut"="_Invoke@12"
"Run time check function"="_RTC_CheckEsp"


Don't step into TAO reference counted pointers:

"TAO_vars"="TAO_Objref_Var_T.*\\:\\:in=NoStepInto"
"TAO_seq_var"="TAO_Seq_Var_Base_T.*\\:\\:.*=NoStepInto"


Don't step into STL:

"std_string_c_str"="std\\:\\:basic_string.*\\:\\:.*=NoStepInto"
"std::list"="std\\:\\:list.*\\:\\:.*=NoStepInto"
"std::vector"="std\\:\\:vector.*\\:\\:.*=NoStepInto"
"std::map"="std\\:\\:map.*\\:\\:.*=NoStepInto"
"std::set"="std\\:\\:set.*\\:\\:.*=NoStepInto"


Don't step into boost::foreach and boost::shared_ptr (could be very usefull within code like
foreach(Object& obj, getObject())
'step-into' goes to getObject() instead of boost internals)

"boost_foreach"="boost\\:\\:foreach_detail_\\:\\:.*=NoStepInto"
"boost_shared_ptr"="boost\\:\\:shared_ptr.*\\:\\:.*=NoStepInto"

Don't step into 'dynamic_cast'

"RTDynamicCast"="__RTDynamicCast=NoStepInfo"
Here are my configuration: dbg.reg

 

3. Debugger Visualizers for Qt generic container types



;------------------------------------------------------------------------------
; QList,QQueue
;------------------------------------------------------------------------------
QList<*>|QQueue<*>{
children
(
#array
(
expr : *($T1*)(($c.d->array+$c.d->begin)[$i]),
size : $c.d->end-$c.d->begin
)
)

preview
(
#(
"[",
$e.d->end - $e.d->begin ,
"](",

#array
(
expr : *($T1*)(($c.d->array+$c.d->begin)[$i]),
size : $c.d->end-$c.d->begin
),
")"
)
)


}

;------------------------------------------------------------------------------
; QList::iterator, QQueue::iterator
;------------------------------------------------------------------------------
QList<*>::iterator|QList<*>::const_iterator|QQueue<*>::iterator|QQueue<*>::const_iterator {

preview
(
#(*($T1*)$e.i->v)
)

children
(
#(ptr: *($T1*)$e.i->v)
)

}

;------------------------------------------------------------------------------
; QListIterator
;------------------------------------------------------------------------------
QListIterator<*>|QMutableListIterator<*> {

preview
(
#(*($T1*)$e.i.i->v)
)

children
(
#(ptr: *($T1*)$e.i.i->v)
)

}


;------------------------------------------------------------------------------
; QVector::iterator, QStack::iterator
;------------------------------------------------------------------------------
QVector<*>::iterator|QVector<*>::const_iterator|QStack<*>::iterator|QStack<*>::const_iterator {

preview
(
#($e.i)
)

children
(
#(ptr: $e.i)
)

}

;------------------------------------------------------------------------------
; QVector, QStack
;------------------------------------------------------------------------------
QVector<*>|QStack<*>{
children
(
#array
(
expr : $c.d->array[$i],
size : $c.d->size
)
)

preview
(
#(
"[",
$e.d->size ,
"](",

#array
(
expr : $c.d->array[$i],
size : $c.d->size
),
")"
)
)


}

;------------------------------------------------------------------------------
; QLinkedList
;------------------------------------------------------------------------------
QLinkedList<*>{
children
(
#list
(
head : $c.d->n,
size : $c.d->size,
next : n
) : #( (*(QLinkedListNode<$T1>*)&$e).t )
)

preview
(
#(
"[",
$e.d->size ,
"](",
#list
(
head : $c.d->n,
size : $c.d->size,
next : n
) : ( (*(QLinkedListNode<$T1>*)&amp;amp;amp;$e).t ),
")"
)
)


}

;------------------------------------------------------------------------------
; QLinkedList::iterator
;------------------------------------------------------------------------------
QLinkedList<*>::iterator|QLinkedList<*>::const_iterator{
preview
(
#($e.i->t)
)

children
(
#(ptr: $e.i->t)
)

}

;------------------------------------------------------------------------------
; QMap::Node
;------------------------------------------------------------------------------
QMap<*,*>::Node{
preview
(
#(
"(",
$e.key,
"; ",
$e.value,
")"
)
)

children
(
#(
key: $e.key,
value: $e.value
)
)

}

;------------------------------------------------------------------------------
; QMap::iterator
;------------------------------------------------------------------------------
QMap<*>::iterator|QMap<*>::const_iterator{
preview
(
#(
(QMap<$T1>::Node*)((char*)$e.i - (sizeof(*(QMap<$T1>::PayloadNode*)0) - sizeof(QMapData::Node*)))
)
)

children
(
#(
node: (QMap<$T1>::Node*)((char*)$e.i - (sizeof(*(QMap<$T1>::PayloadNode*)0) - sizeof(QMapData::Node*)))
)
)

}

;------------------------------------------------------------------------------
; QMap
;------------------------------------------------------------------------------

QMap<*>{
children
(
#tree
(
head : $c.d->forward[0],
skip : $c.d,
size : $c.d->size,
left : backward,
right : forward
) : ( (QMap<$T1>::Node*)((char*)&$e - (sizeof(*(QMap<$T1>::PayloadNode*)0) - sizeof(QMapData::Node*))) )
)

preview
(
#(
"[",
$e.d->size,
"](",

#tree
(
head : $c.d->forward,
size : $c.d->size,
left : backward,
right : forward
) : $e,

")"
)
)
}


To use these visualizers they should be pasted into "c:\Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger\autoexp.dat"

Here are some articles about configuring visualizers for STLport: Garry's Brain Blog

These tips are written in short just not to forget.

5 comments:

Garry Bodsworth said...

Hi there,

Just thought I'd return the favour!

It looks like a great thing for Qt programmers and will make a lot of developers lives a lot easier.

Anonymous said...

Hi,

I tried "Debugger Visualizers for Qt generic container types". I've got an error message (syntax error near end of block, caused by a bracket, the error message shows that line which contains }) in QLinkedList block. If I comment this block, it's OK.

Do you have any idea?

Peter

shadone said...

looks like the problem is in html-escaping - I pasted code with blogger html preview mode and it didn't escaped some symbols correctly. I'll fix it.

And by the way - these visualizers has a bug - they don't work for QList<int> - since QList has some optimizations when contained type is a small type ('small' I mean less than sizeof(void*)). I have plans to try to fix this, but I am not sure when.

Anonymous said...

I use Qt4.5, Visual Studio2008
My PC can't display QMap key,value.
autoexp.dat of qt-vs-addin-1.0.0-rc1.exe
can't display too. I tried to fix QMap rule,
but it is very diffcult. So I can't as yet.
I will try more, but please could you make it?
Thank you.
Machiyuta

Leviana said...

I have a blog about medicines without prescription so I need to see the debug mode of the blog, do you know how to do it.

Denis Dzyubenko shadone