Skip to content

Commit 51178d9

Browse files
committed
Eliminate seg fault for recursive print
1 parent a864f9d commit 51178d9

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/sst/core/impl/interactive/simpleDebug.cc

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -743,41 +743,34 @@ SimpleDebugger::cmd_print(std::vector<std::string>& tokens)
743743
// See if have a -r or not
744744
int recurse = 0;
745745
std::string tok = tokens[1];
746-
if ( tok.size() >= 2 && tok[0] == '-' && tok[1] == 'r' ) {
746+
if ( (tok.size() >= 2) && (tok[0] == '-') && (tok[1] == 'r') ) {
747747
// Got a -r
748-
std::string num = tok.substr(2);
749-
if ( num.size() != 0 ) {
750-
try {
751-
recurse = SST::Core::from_string<int>(num);
752-
}
753-
catch ( std::invalid_argument& e ) {
754-
printf("Invalid number format specified with -r: %s\n", tok.c_str());
755-
return;
748+
if (tok.size() == 2) {
749+
recurse = 4;
750+
} else {
751+
std::string num = tok.substr(2);
752+
if (num.size() != 0) {
753+
try {
754+
recurse = SST::Core::from_string<int>(num);
755+
}
756+
catch (std::invalid_argument& e) {
757+
printf("Invalid number format specified with -r: %s\n", tok.c_str());
758+
return;
759+
}
756760
}
757761
}
758-
else {
759-
recurse = 4; // default -r depth
760-
}
761-
762762
var_index = 2;
763763
}
764764

765-
if ( tokens.size() == var_index ) {
766-
// Print current object
767-
obj_->list(recurse);
768-
return;
769-
}
770-
771765
if ( tokens.size() != (var_index + 1) ) {
772766
printf("Invalid format for print command (print [-rN] [<obj>])\n");
773767
return;
774768
}
775769

776770
bool found;
777771
std::string listing = obj_->listVariable(tokens[var_index], found, recurse);
778-
779772
if ( !found ) {
780-
printf("Unknown object in print command: %s\n", tokens[1].c_str());
773+
printf("Unknown object in print command: %s\n", tokens[var_index].c_str());
781774
return;
782775
}
783776
else {

src/sst/core/serialization/objectMap.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ ObjectMap::demangle_name(const char* name)
176176
std::string
177177
ObjectMap::listVariable(std::string name, bool& found, int recurse)
178178
{
179+
auto& vars = getVariables();
179180
ObjectMap* var = findVariable(name);
180181
if ( nullptr == var ) {
181182
found = false;
182183
return "";
183184
}
184185
found = true;
185186

187+
186188
std::string ret;
187189

188190
// Check to see if this is a loopback
@@ -213,7 +215,6 @@ ObjectMap::listRecursive(const std::string& name, int level, int recurse)
213215
ret = format_string("%s%s = %s (%s)\n", indent.c_str(), name.c_str(), get().c_str(), getType().c_str());
214216
return ret;
215217
}
216-
217218
ret = format_string("%s%s (%s)\n", indent.c_str(), name.c_str(), getType().c_str());
218219

219220
if ( level <= recurse ) {

0 commit comments

Comments
 (0)