Commit 90e4dd03 authored by rdubner's avatar rdubner
Browse files

Refactor cobcd.py with the 'MetaPossibilities' routine.

parent 2d31bc72
......@@ -172,7 +172,7 @@ CreateSymc(PARAMETERS &params,
seg += ch;
}
size_t nfound_comment = seg.find("#");
if( !in_copyright AND nfound_comment != string::npos ) {
if(false AND !in_copyright AND nfound_comment != string::npos ) {
// There is a pound sign, which is the Python comment signal
size_t nfound_quote = seg.find_first_of("'\"");
if( nfound_quote > nfound_comment ) {
......@@ -181,7 +181,8 @@ CreateSymc(PARAMETERS &params,
}
}
if( !Trim(seg).empty() ) {
//if( !Trim(seg).empty() )
{
seg += '\n';
size_t t = strlen(py);
strcpy(py+t,seg.c_str());
......
......@@ -446,7 +446,7 @@ class VarTrie() :
#
# and terminate
return
def GetAllPossibilities(self) :
# Typically in response to a 'print *'
paths = []
......@@ -2804,6 +2804,94 @@ class ShortTermMemory() :
GV_ShortTermMemory = ShortTermMemory()
def MetaPossibilities(args,TabFile,ShortTermMemory,machine_interface_mode) :
if len(args) >= 1 :
if args[0] == '*' :
# If the first, presumably single, argument is an asterisk, then
# he is asking for a list of variables and values:
possibilities = TabFile.var_trie.GetAllPossibilities()
elif args[0].isdigit() :
# if the first, presumably single, argument is a number, then he is looking
# for a short_term_memory entry.
# Pick up the 1-based value indexed by the argument:
index = int(args[0])-1
if index >= 0 and index < len(ShortTermMemory.short_term_memory) :
# If index is valid, pick up the short-term memory entry
possibilities = [ShortTermMemory.short_term_memory[index]]
else :
# There are one or more arguments. Use our clever routine
# to come up with the possibilities:
possibilities = TabFile.var_trie.GetListOfPossibilities(args)
# What we do now depends on how many possibilities there are
if len(possibilities) > 1 :
# There is more than one possibility:
if machine_interface_mode :
# This is machine interface mode
# Our mission is to emulate the
# '-stack-list-variables --simple-values'
s = "variables=["
for payload_index in possibilities :
payload = TabFile.var_trie.storage_list[payload_index]
payload.FetchVariableData(TabFile.line_list , False)
if not payload.not_in_context :
name = ""
name += payload.display_name;
n = name.find(' ')
if n > -1 :
name = name[:n] + '-' + name[n+1:]
n = name.find(' ')
if n > -1 :
name = name[:n]
# Everything after the final slash is the program
# name, which is redundant and takes up valuable
# screen real estate. Clear it out.
n = name.rfind('/')
if n > -1 :
name = name[:n]
body , body_length = MachineInterfaceBody(payload.display_body)
s += '{name="'
s += name
s += '"'
s += ',type="char *"'
s += r',value="'
s += payload.location
s += r' \"'
s += body
s += r'\""},'
if s[-1] == ',' :
s = s[:-1] # Strip off final comma
s += ']'
print(NoNulls(s))
else :
ShortTermMemory.short_term_memory = []
# This is human-interactive mode
# and show them to our user
line_counter = 1
for payload_index in possibilities :
payload = TabFile.var_trie.storage_list[payload_index]
payload.FetchVariableData(TabFile.line_list , False)
if not payload.not_in_context :
ShortTermMemory.short_term_memory.append(payload_index)
s = "{0:2} : ".format(line_counter)
s += payload.display_name
s += " : "
s += payload.display_body
print(NoNulls(s))
line_counter += 1
return possibilities
# Note on the program structure:
#
# The Python extension to gdb is plenty powerful, but it is infuriating
......@@ -2917,28 +3005,7 @@ class CPrintWorker() :
args = self.ProcessDisplayMode(args)
possibilities = []
if len(args) >= 1 :
if args[0] == '*' :
# If the first, presumably single, argument is an asterisk, then
# he is asking for a list of variables and values:
possibilities = TabFile.var_trie.GetAllPossibilities()
elif args[0].isdigit() :
# if the first, presumably single, argument is a number, then he is looking
# for a short_term_memory entry.
# Pick up the 1-based value indexed by the argument:
index = int(args[0])-1
if index >= 0 and index < len(ShortTermMemory.short_term_memory) :
# If index is valid, pick up the short-term memory entry
possibilities = [ShortTermMemory.short_term_memory[index]]
else :
# There are one or more arguments. Use our clever routine
# to come up with the possibilities:
possibilities = TabFile.var_trie.GetListOfPossibilities(args)
# What we do now depends on how many possibilities there are
possibilities = MetaPossibilities(args,TabFile,ShortTermMemory,self.machine_interface_mode)
if len(possibilities) == 1 :
# There is but one possibility
# Pick up the payload from the list
......@@ -2960,70 +3027,6 @@ class CPrintWorker() :
# Human-interface:
# And display the variable according to the current list v-level
self.FormattedDisplay(payload)
else :
# There is more than one possibility:
if self.machine_interface_mode :
# This is machine interface mode
# Our mission is to emulate the
# '-stack-list-variables --simple-values'
s = "variables=["
for payload_index in possibilities :
payload = TabFile.var_trie.storage_list[payload_index]
payload.FetchVariableData(TabFile.line_list , False)
if not payload.not_in_context :
name = ""
name += payload.display_name;
n = name.find(' ')
if n > -1 :
name = name[:n] + '-' + name[n+1:]
n = name.find(' ')
if n > -1 :
name = name[:n]
# Everything after the final slash is the program
# name, which is redundant and takes up valuable
# screen real estate. Clear it out.
n = name.rfind('/')
if n > -1 :
name = name[:n]
body , body_length = MachineInterfaceBody(payload.display_body)
s += '{name="'
s += name
s += '"'
s += ',type="char *"'
s += r',value="'
s += payload.location
s += r' \"'
s += body
s += r'\""},'
if s[-1] == ',' :
s = s[:-1] # Strip off final comma
s += ']'
print(NoNulls(s))
else :
ShortTermMemory.short_term_memory = []
# This is human-interactive mode
# and show them to our user
line_counter = 1
for payload_index in possibilities :
payload = TabFile.var_trie.storage_list[payload_index]
payload.FetchVariableData(TabFile.line_list , False)
if not payload.not_in_context :
ShortTermMemory.short_term_memory.append(payload_index)
s = "{0:2} : ".format(line_counter)
s += payload.display_name
s += " : "
s += payload.display_body
print(NoNulls(s))
line_counter += 1
class CWatchWorker() :
"""Does most of the non-gdb work of CWatch()"""
......@@ -3089,67 +3092,10 @@ class CWatchWorker() :
args = arguments.split()
args = self.ProcessDisplayModeW(args)
payload_number = None
pstar = False
if len(args) == 1 :
if args[0] == '*' :
pstar = True
# If the single argument is an asterisk, then
# he is asking for a list of variables and values:
args[0] = TabFile.current_trapped_routine
elif args[0].isdigit() :
# if the single argument is a number, then he is looking
# for a short_term_memory entry. If the short-term entry is
# alphabetic, then it is a reference to a program-id. If it
# is numeric, it's a payload number
# Pick up the value indexed by the argument:
index = int(args[0])
if index > 0 and index <= len(ShortTermMemory.short_term_memory) :
# If index is valid, pick up the short-term memory entry
short_term_entry = ShortTermMemory.short_term_memory[index-1]
if isinstance(short_term_entry, int) :
# It is an integer; look up the payload number:
payload_number = ShortTermMemory.short_term_memory[index-1]
else :
# It is text, meaning it is a program-id. Pass it
# along for expansion
args[0] = short_term_entry
possibilities = MetaPossibilities(args,TabFile,ShortTermMemory, False)
if len(args) >= 1 :
if payload_number == None :
# There are one or more arguments. Use our clever routine
# to come up with the possibilities:
possibilities = TabFile.var_trie.GetListOfPossibilities(args)
if len(possibilities) == 1 and not pstar:
# There's only one possibility, and it wasn't a star.
# This is nice and simple.
# We'll just move ahead and process it.
payload_number = possibilities[0]
elif len(possibilities) > 1 or (len(possibilities) > 0 and pstar) :
# There are multiple possibilities, or there is one
# possibility found via a 'p *'.
# Load them into short-term memory:
ShortTermMemory.short_term_memory = possibilities
# and show them to our user
line_counter = 1
for payload_index in possibilities :
payload = TabFile.var_trie.storage_list[payload_index]
payload.FetchVariableData(TabFile.line_list , False)
if not payload.not_in_context :
s = "{0:2} : ".format(line_counter)
s += payload.display_name
s += " : "
s += payload.display_body
print(NoNulls(s))
line_counter += 1
# At this point, if we have a single payload, it's time to show
# that to our user:
if payload_number != None :
if len(possibilities) == 1 :
payload_number = possibilities[0]
#print("Watch Payload number is ", payload_number)
# Pick up the payload from the list
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment