Files
clang-p2996/lldb/test/functionalities/format/TestFormats.py
Greg Clayton 554f68d385 Get rid of Debugger::FormatPrompt() and replace it with the new FormatEntity class.
Why? Debugger::FormatPrompt() would run through the format prompt every time and parse it and emit it piece by piece. It also did formatting differently depending on which key/value pair it was parsing. 

The new code improves on this with the following features:
1 - Allow format strings to be parsed into a FormatEntity::Entry which can contain multiple child FormatEntity::Entry objects. This FormatEntity::Entry is a parsed version of what was previously always done in Debugger::FormatPrompt() so it is more efficient to emit formatted strings using the new parsed FormatEntity::Entry.
2 - Allows errors in format strings to be shown immediately when setting the settings (frame-format, thread-format, disassembly-format
3 - Allows auto completion by implementing a new OptionValueFormatEntity and switching frame-format, thread-format, and disassembly-format settings over to using it.
4 - The FormatEntity::Entry for each of the frame-format, thread-format, disassembly-format settings only replaces the old one if the format parses correctly
5 - Combines all consecutive string values together for efficient output. This means all "${ansi.*}" keys and all desensitized characters like "\n" "\t" "\0721" "\x23" will get combined with their previous strings
6 - ${*.script:} (like "${var.script:mymodule.my_var_function}") have all been switched over to use ${script.*:} "${script.var:mymodule.my_var_function}") to make the format easier to parse as I don't believe anyone was using these format string power user features.
7 - All key values pairs are defined in simple C arrays of entries so it is much easier to add new entries.

These changes pave the way for subsequent modifications where we can modify formats to do more (like control the width of value strings can do more and add more functionality more easily like string formatting to control the width, printf formats and more).

llvm-svn: 228207
2015-02-04 22:00:53 +00:00

63 lines
2.3 KiB
Python

"""
Test the command history mechanism
"""
import os
import unittest2
import lldb
from lldbtest import *
class TestFormats(TestBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
def test_formats(self):
"""Test format string functionality."""
self.buildDwarf ()
import pexpect
prompt = "(lldb) "
child = pexpect.spawn('%s %s -x -o "b main" -o r a.out' % (self.lldbHere, self.lldbOption))
# Turn on logging for what the child sends back.
if self.TraceOn():
child.logfile_read = sys.stdout
# So that the spawned lldb session gets shutdown durng teardown.
self.child = child
# Substitute 'Help!' for 'help' using the 'commands regex' mechanism.
child.expect_exact(prompt + 'target create "a.out"')
child.expect_exact(prompt + 'b main')
child.expect_exact(prompt + 'r')
child.expect_exact(prompt)
child.sendline()
# child.expect_exact(prompt + "target create")
#
# child.sendline("command regex 'Help__'")
# child.expect_exact(regex_prompt)
# child.sendline('s/^$/help/')
# child.expect_exact(regex_prompt1)
# child.sendline('')
# child.expect_exact(prompt)
# # Help!
# child.sendline('Help__')
# # If we see the familiar 'help' output, the test is done.
# child.expect('Debugger commands:')
# # Try and incorrectly remove "Help__" using "command unalias" and verify we fail
# child.sendline('command unalias Help__')
# child.expect_exact("error: 'Help__' is not an alias, it is a debugger command which can be removed using the 'command delete' command")
# child.expect_exact(prompt)
#
# # Delete the regex command using "command delete"
# child.sendline('command delete Help__')
# child.expect_exact(prompt)
# # Verify the command was removed
# child.sendline('Help__')
# child.expect_exact("error: 'Help__' is not a valid command")
# child.expect_exact(prompt)
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()