Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
7898a499
Commit
7898a499
authored
Dec 12, 2008
by
hjk
Browse files
add custom dumper for std::map
parent
5b8cff20
Changes
3
Hide whitespace changes
Inline
Side-by-side
bin/gdbmacros/gdbmacros.cpp
View file @
7898a499
...
...
@@ -123,6 +123,7 @@ int qtGhVersion = QT_VERSION;
#endif
#include <list>
#include <map>
#include <string>
#include <vector>
...
...
@@ -291,7 +292,7 @@ static bool startsWith(const char *s, const char *t)
#define qCheckAccess(d) do { qProvokeSegFaultHelper = *(char*)d; } while (0)
#define qCheckPointer(d) do { if (d) qProvokeSegFaultHelper = *(char*)d; } while (0)
// provoke segfault unconditionally
#define qCheck(b) do { if (!
b
) qProvokeSegFaultHelper = *(char*)0; } while (0)
#define qCheck(b) do { if (!
(b)
) qProvokeSegFaultHelper = *(char*)0; } while (0)
const
char
*
stripNamespace
(
const
char
*
type
)
{
...
...
@@ -2146,6 +2147,61 @@ static void qDumpStdList(QDumper &d)
d
.
disarm
();
}
static
void
qDumpStdMap
(
QDumper
&
d
)
{
const
std
::
map
<
int
,
int
>
&
map
=
*
reinterpret_cast
<
const
std
::
map
<
int
,
int
>
*>
(
d
.
data
);
const
char
*
keyType
=
d
.
templateParameters
[
0
];
const
char
*
valueType
=
d
.
templateParameters
[
1
];
const
void
*
p
=
d
.
data
;
qCheckAccess
(
p
);
p
=
deref
(
p
);
int
nn
=
map
.
size
();
qCheck
(
nn
>=
0
);
std
::
map
<
int
,
int
>::
const_iterator
it
=
map
.
begin
();
for
(
int
i
=
0
;
i
<
nn
&&
i
<
10
&&
it
!=
map
.
end
();
++
i
,
++
it
)
qCheckAccess
(
it
.
operator
->
());
QByteArray
strippedInnerType
=
stripPointerType
(
d
.
innertype
);
P
(
d
,
"numchild"
,
nn
);
P
(
d
,
"value"
,
"<"
<<
nn
<<
" items>"
);
P
(
d
,
"valuedisabled"
,
"true"
);
P
(
d
,
"valueoffset"
,
d
.
extraInt
[
2
]);
if
(
d
.
dumpChildren
)
{
bool
simpleKey
=
isSimpleType
(
keyType
);
bool
simpleValue
=
isShortKey
(
valueType
);
int
valueOffset
=
d
.
extraInt
[
2
];
d
<<
",children=["
;
std
::
map
<
int
,
int
>::
const_iterator
it
=
map
.
begin
();
for
(
int
i
=
0
;
i
<
1000
&&
it
!=
map
.
end
();
++
i
,
++
it
)
{
const
void
*
node
=
it
.
operator
->
();
if
(
simpleKey
)
{
d
.
beginHash
();
P
(
d
,
"type"
,
valueType
);
qDumpInnerValueHelper
(
d
,
keyType
,
node
,
"name"
);
P
(
d
,
"nameisindex"
,
"1"
);
if
(
simpleValue
)
qDumpInnerValueHelper
(
d
,
valueType
,
addOffset
(
node
,
valueOffset
));
P
(
d
,
"addr"
,
addOffset
(
node
,
valueOffset
));
d
.
endHash
();
}
else
{
d
.
beginHash
();
P
(
d
,
"name"
,
"["
<<
i
<<
"]"
);
P
(
d
,
"addr"
,
it
.
operator
->
());
P
(
d
,
"type"
,
"std::pair<const "
<<
keyType
<<
","
<<
valueType
<<
" >"
);
d
.
endHash
();
}
}
if
(
it
!=
map
.
end
())
d
.
putEllipsis
();
d
<<
"]"
;
}
d
.
disarm
();
}
static
void
qDumpStdString
(
QDumper
&
d
)
{
const
std
::
string
&
str
=
*
reinterpret_cast
<
const
std
::
string
*>
(
d
.
data
);
...
...
@@ -2356,9 +2412,9 @@ static void handleProtocolVersion2and3(QDumper & d)
qDumpStdVectorBool
(
d
);
else
if
(
isEqual
(
type
,
"std::list"
))
qDumpStdList
(
d
);
else
if
(
isEqual
(
type
,
"st
ring
"
))
qDumpStd
String
(
d
);
else
if
(
isEqual
(
type
,
"std::string"
))
else
if
(
isEqual
(
type
,
"st
d::map
"
))
qDumpStd
Map
(
d
);
else
if
(
isEqual
(
type
,
"std::string"
)
||
isEqual
(
type
,
"string"
)
)
qDumpStdString
(
d
);
else
if
(
isEqual
(
type
,
"std::wstring"
))
qDumpStdWString
(
d
);
...
...
src/plugins/debugger/gdbengine.cpp
View file @
7898a499
...
...
@@ -2941,6 +2941,8 @@ bool GdbEngine::isCustomValueDumperAvailable(const QString &type) const
}
if
(
tmplate
==
"std::list"
)
return
true
;
if
(
tmplate
==
"std::map"
)
return
true
;
if
(
tmplate
==
"std::vector"
&&
inner
!=
"bool"
)
return
true
;
if
(
tmplate
==
"std::basic_string"
)
{
...
...
@@ -2962,6 +2964,8 @@ void GdbEngine::runCustomDumper(const WatchData & data0, bool dumpChildren)
QStringList
inners
=
inner
.
split
(
'@'
);
if
(
inners
.
at
(
0
).
isEmpty
())
inners
.
clear
();
for
(
int
i
=
0
;
i
!=
inners
.
size
();
++
i
)
inners
[
i
]
=
inners
[
i
].
simplified
();
QString
outertype
=
isTemplate
?
tmplate
:
data
.
type
;
...
...
@@ -3015,6 +3019,12 @@ void GdbEngine::runCustomDumper(const WatchData & data0, bool dumpChildren)
//extraArgs[extraArgCount++] = sizeofTypeExpression(data.type);
//extraArgs[extraArgCount++] = "(size_t)&(('" + data.type + "'*)0)->value";
}
}
else
if
(
outertype
==
"std::map"
)
{
// We don't want the comparator and the allocator confuse gdb.
// But we need the offset of the second item in the value pair.
extraArgs
[
2
]
=
"(size_t)&(('std::pair<const "
+
inners
.
at
(
0
)
+
","
+
inners
.
at
(
1
)
+
">'*)0)->second"
;
extraArgs
[
3
]
=
"0"
;
}
else
if
(
outertype
==
"std::basic_string"
)
{
//qDebug() << "EXTRACT TEMPLATE: " << outertype << inners;
if
(
inners
.
at
(
0
)
==
"char"
)
{
...
...
@@ -3064,6 +3074,8 @@ void GdbEngine::runCustomDumper(const WatchData & data0, bool dumpChildren)
+
','
+
extraArgs
[
2
]
+
','
+
extraArgs
[
3
]
+
')'
;
//qDebug() << "CMD: " << cmd;
sendSynchronizedCommand
(
cmd
,
WatchDumpCustomValue1
,
QVariant
::
fromValue
(
data
));
q
->
showStatusMessage
(
...
...
tests/manual/gdbdebugger/simple/app.cpp
View file @
7898a499
...
...
@@ -267,7 +267,7 @@ void testQMap()
ggt
[
11
]
=
QStringList
()
<<
"11"
;
ggt
[
22
]
=
QStringList
()
<<
"22"
;
#if
0
#if
1
QMap
<
uint
,
float
>
gg0
;
gg0
[
11
]
=
11.0
;
gg0
[
22
]
=
22.0
;
...
...
@@ -413,16 +413,31 @@ void testStdList()
void
testStdMap
()
{
std
::
map
<
QString
,
Foo
>
gg3
;
gg3
[
"22.0"
]
=
Foo
(
22
);
gg3
[
"33.0"
]
=
Foo
(
33
);
gg3
[
"44.0"
]
=
Foo
(
44
);
#if 1
std
::
map
<
uint
,
uint
>
gg
;
gg
[
11
]
=
1
;
gg
[
22
]
=
2
;
gg
[
33
]
=
3
;
gg
[
44
]
=
4
;
gg
[
55
]
=
5
;
std
::
map
<
uint
,
QStringList
>
ggl
;
ggl
[
11
]
=
QStringList
()
<<
"11"
;
ggl
[
22
]
=
QStringList
()
<<
"22"
;
ggl
[
33
]
=
QStringList
()
<<
"33"
;
ggl
[
44
]
=
QStringList
()
<<
"44"
;
ggl
[
55
]
=
QStringList
()
<<
"55"
;
typedef
std
::
map
<
uint
,
QStringList
>
T
;
T
ggt
;
ggt
[
11
]
=
QStringList
()
<<
"11"
;
ggt
[
22
]
=
QStringList
()
<<
"22"
;
#if 0
std
::
map
<
uint
,
float
>
gg0
;
gg0
[
11
]
=
11.0
;
gg0
[
22
]
=
22.0
;
...
...
@@ -434,15 +449,11 @@ void testStdMap()
std
::
map
<
int
,
QString
>
gg2
;
gg2
[
22
]
=
"22.0"
;
std::map<QString, Foo> gg3;
gg3["22.0"] = Foo(22);
gg3["33.0"] = Foo(33);
QObject
ob
;
std
::
map
<
QString
,
QPointer
<
QObject
>
>
map
;
map
.insert(
"Hallo"
,
QPointer<QObject>(&ob)
)
;
map
.insert(
"Welt"
,
QPointer<QObject>(&ob)
)
;
map
.insert(".",
QPointer<QObject>(&ob)
)
;
map
[
"Hallo"
]
=
QPointer
<
QObject
>
(
&
ob
);
map
[
"Welt"
]
=
QPointer
<
QObject
>
(
&
ob
);
map
[
"."
]
=
QPointer
<
QObject
>
(
&
ob
);
#endif
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment