an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
261 lines
11 KiB
Python
261 lines
11 KiB
Python
"""
|
|
Test lldb settings command.
|
|
"""
|
|
|
|
import os, time
|
|
import unittest2
|
|
import lldb
|
|
from lldbtest import *
|
|
|
|
class SettingsCommandTestCase(TestBase):
|
|
|
|
mydir = "settings"
|
|
|
|
@classmethod
|
|
def classCleanup(cls):
|
|
"""Cleanup the test byproducts."""
|
|
system(["/bin/sh", "-c", "rm -f output1.txt"])
|
|
system(["/bin/sh", "-c", "rm -f output2.txt"])
|
|
system(["/bin/sh", "-c", "rm -f stderr.txt"])
|
|
system(["/bin/sh", "-c", "rm -f stdout.txt"])
|
|
|
|
def test_apropos_should_also_search_settings_description(self):
|
|
"""Test that 'apropos' command should also search descriptions for the settings variables."""
|
|
|
|
self.expect("apropos 'environment variable'",
|
|
substrs = ["target.process.env-vars",
|
|
"environment variables",
|
|
"executable's environment"])
|
|
|
|
def test_set_prompt(self):
|
|
"""Test that 'set prompt' actually changes the prompt."""
|
|
|
|
# Set prompt to 'lldb2'.
|
|
self.runCmd("settings set prompt lldb2")
|
|
|
|
# Immediately test the setting.
|
|
self.expect("settings show prompt", SETTING_MSG("prompt"),
|
|
startstr = "prompt (string) = 'lldb2'")
|
|
|
|
# The overall display should also reflect the new setting.
|
|
self.expect("settings show", SETTING_MSG("prompt"),
|
|
substrs = ["prompt (string) = 'lldb2'"])
|
|
|
|
# Use '-r' option to reset to the original default prompt.
|
|
self.runCmd("settings set -r prompt")
|
|
|
|
def test_set_term_width(self):
|
|
"""Test that 'set term-width' actually changes the term-width."""
|
|
|
|
self.runCmd("settings set term-width 70")
|
|
|
|
# Immediately test the setting.
|
|
self.expect("settings show term-width", SETTING_MSG("term-width"),
|
|
startstr = "term-width (int) = '70'")
|
|
|
|
# The overall display should also reflect the new setting.
|
|
self.expect("settings show", SETTING_MSG("term-width"),
|
|
substrs = ["term-width (int) = '70'"])
|
|
|
|
def test_set_auto_confirm(self):
|
|
"""Test that after 'set auto-confirm true', manual confirmation should not kick in."""
|
|
self.buildDefault()
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
self.runCmd("settings set auto-confirm true")
|
|
|
|
# Immediately test the setting.
|
|
self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
|
|
startstr = "auto-confirm (boolean) = 'true'")
|
|
|
|
# Now 'breakpoint delete' should just work fine without confirmation
|
|
# prompt from the command interpreter.
|
|
self.runCmd("breakpoint set -n main")
|
|
self.expect("breakpoint delete",
|
|
startstr = "All breakpoints removed")
|
|
|
|
# Restore the original setting of auto-confirm.
|
|
self.runCmd("settings set -r auto-confirm")
|
|
self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
|
|
startstr = "auto-confirm (boolean) = 'false'")
|
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
|
def test_run_args_and_env_vars_with_dsym(self):
|
|
"""Test that run-args and env-vars are passed to the launched process."""
|
|
self.buildDsym()
|
|
self.pass_run_args_and_env_vars()
|
|
|
|
def test_run_args_and_env_vars_with_dwarf(self):
|
|
"""Test that run-args and env-vars are passed to the launched process."""
|
|
self.buildDwarf()
|
|
self.pass_run_args_and_env_vars()
|
|
|
|
def pass_run_args_and_env_vars(self):
|
|
"""Test that run-args and env-vars are passed to the launched process."""
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
# Set the run-args and the env-vars.
|
|
# And add hooks to restore the settings during tearDown().
|
|
self.runCmd('settings set target.process.run-args A B C')
|
|
self.addTearDownHook(
|
|
lambda: self.runCmd("settings set -r target.process.run-args"))
|
|
self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES')
|
|
self.addTearDownHook(
|
|
lambda: self.runCmd("settings set -r target.process.env-vars"))
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
# Read the output file produced by running the program.
|
|
with open('output2.txt', 'r') as f:
|
|
output = f.read()
|
|
|
|
self.expect(output, exe=False,
|
|
substrs = ["argv[1] matches",
|
|
"argv[2] matches",
|
|
"argv[3] matches",
|
|
"Environment variable 'MY_ENV_VAR' successfully passed."])
|
|
|
|
def test_pass_host_env_vars(self):
|
|
"""Test that the host env vars are passed to the launched process."""
|
|
self.buildDefault()
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
# By default, inherit-env is 'true'.
|
|
self.expect('settings show target.process.inherit-env', "Default inherit-env is 'true'",
|
|
startstr = "target.process.inherit-env (boolean) = 'true'")
|
|
|
|
# Set some host environment variables now.
|
|
os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
|
|
os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
|
|
|
|
# This is the function to unset the two env variables set above.
|
|
def unset_env_variables():
|
|
os.environ.pop("MY_HOST_ENV_VAR1")
|
|
os.environ.pop("MY_HOST_ENV_VAR2")
|
|
|
|
self.addTearDownHook(unset_env_variables)
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
# Read the output file produced by running the program.
|
|
with open('output1.txt', 'r') as f:
|
|
output = f.read()
|
|
|
|
self.expect(output, exe=False,
|
|
substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
|
|
"The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
|
|
|
|
def test_set_error_output_path(self):
|
|
"""Test that setting target.process.error/output-path for the launched process works."""
|
|
self.buildDefault()
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
# Set the error-path and output-path and verify both are set.
|
|
self.runCmd("settings set target.process.error-path stderr.txt")
|
|
self.runCmd("settings set target.process.output-path stdout.txt")
|
|
# And add hooks to restore the original settings during tearDown().
|
|
self.addTearDownHook(
|
|
lambda: self.runCmd("settings set -r target.process.output-path"))
|
|
self.addTearDownHook(
|
|
lambda: self.runCmd("settings set -r target.process.error-path"))
|
|
|
|
self.expect("settings show target.process.error-path",
|
|
SETTING_MSG("target.process.error-path"),
|
|
startstr = "target.process.error-path (string) = 'stderr.txt'")
|
|
|
|
self.expect("settings show target.process.output-path",
|
|
SETTING_MSG("target.process.output-path"),
|
|
startstr = "target.process.output-path (string) = 'stdout.txt'")
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
# The 'stderr.txt' file should now exist.
|
|
self.assertTrue(os.path.isfile("stderr.txt"),
|
|
"'stderr.txt' exists due to target.process.error-path.")
|
|
|
|
# Read the output file produced by running the program.
|
|
with open('stderr.txt', 'r') as f:
|
|
output = f.read()
|
|
|
|
self.expect(output, exe=False,
|
|
startstr = "This message should go to standard error.")
|
|
|
|
# The 'stdout.txt' file should now exist.
|
|
self.assertTrue(os.path.isfile("stdout.txt"),
|
|
"'stdout.txt' exists due to target.process.output-path.")
|
|
|
|
# Read the output file produced by running the program.
|
|
with open('stdout.txt', 'r') as f:
|
|
output = f.read()
|
|
|
|
self.expect(output, exe=False,
|
|
startstr = "This message should go to standard out.")
|
|
|
|
def test_print_dictionary_setting(self):
|
|
self.runCmd ("settings set -r target.process.env-vars")
|
|
self.runCmd ("settings set target.process.env-vars [\"MY_VAR\"]=some-value")
|
|
self.expect ("settings show target.process.env-vars",
|
|
substrs = [ "'MY_VAR=some-value'" ])
|
|
self.runCmd ("settings set -r target.process.env-vars")
|
|
|
|
def test_print_array_setting(self):
|
|
self.runCmd ("settings set -r target.process.run-args")
|
|
self.runCmd ("settings set target.process.run-args gobbledy-gook")
|
|
self.expect ("settings show target.process.run-args",
|
|
substrs = [ "[0]: 'gobbledy-gook'" ])
|
|
self.runCmd ("settings set -r target.process.run-args")
|
|
|
|
def test_settings_with_quotes (self):
|
|
self.runCmd ("settings set -r target.process.run-args")
|
|
self.runCmd ("settings set target.process.run-args a b c")
|
|
self.expect ("settings show target.process.run-args",
|
|
substrs = [ "[0]: 'a'",
|
|
"[1]: 'b'",
|
|
"[2]: 'c'" ])
|
|
self.runCmd ("settings set target.process.run-args 'a b c'")
|
|
self.expect ("settings show target.process.run-args",
|
|
substrs = [ "[0]: 'a b c'" ])
|
|
self.runCmd ("settings set -r target.process.run-args")
|
|
self.runCmd ("settings set -r target.process.env-vars")
|
|
self.runCmd ("settings set target.process.env-vars [\"MY_FILE\"]='this is a file name with spaces.txt'")
|
|
self.expect ("settings show target.process.env-vars",
|
|
substrs = [ "'MY_FILE=this is a file name with spaces.txt'" ])
|
|
self.runCmd ("settings set -r target.process.env-vars")
|
|
|
|
|
|
def test_all_settings_exist (self):
|
|
self.expect ("settings show",
|
|
substrs = [ "frame-format (string) = ",
|
|
"prompt (string) = ",
|
|
"script-lang (string) = ",
|
|
"term-width (int) = ",
|
|
"thread-format (string) = ",
|
|
"use-external-editor (boolean) = ",
|
|
"auto-confirm (boolean) = ",
|
|
"target.default-arch (string):",
|
|
"target.expr-prefix (string) = ",
|
|
"target.process.run-args (array):",
|
|
"target.process.env-vars (dictionary):",
|
|
"target.process.inherit-env (boolean) = ",
|
|
"target.process.input-path (string) = ",
|
|
"target.process.output-path (string) = ",
|
|
"target.process.error-path (string) = ",
|
|
"target.process.plugin (enum):",
|
|
"target.process.disable-aslr (boolean) = ",
|
|
"target.process.disable-stdio (boolean) = ",
|
|
"target.process.thread.step-avoid-regexp (string):",
|
|
"target.process.thread.trace-thread (boolean) =" ])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import atexit
|
|
lldb.SBDebugger.Initialize()
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
unittest2.main()
|