Files
clang-p2996/lldb/source/Breakpoint/BreakpointLocation.cpp
Ilia K 9b618d25ca Generate an event when a pending breakpoint binds
Summary:
This checkin sends an MI event when a module is loaded that causes a pending breakpoint to bind to it's real address in the target. This allows breakpoints to be set before the process is launched, and the target address of the BP to be discovered when the module loads, prior to the breakpoint being hit. 

Patch from chuckr@microsoft.com

Test Plan:
I ran the check-lldb target with and without this patch and saw no change. I am unsure of how to write an MI specific test for this because the new event is buried in module load events. Here is an example (the new event is in bold):


```
(gdb)
-file-exec-and-symbols a.out
^done
(gdb)
=shlibs-added,shlib-info=[num="1",name="a.out",dyld-addr="-",reason="dyld",path="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/a.out",loaded_addr="-",dsym-objpath="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/a.out.dSYM/Contents/Resources/DWARF/a.out"]
-break-insert -f main.cpp:15
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0xffffffffffffffff",func="main",file="main.cpp",fullname="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/main.cpp",line="15",pending=["main.cpp:15"],times="0",original-location="main.cpp:15"}
(gdb)
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0xffffffffffffffff",func="main",file="main.cpp",fullname="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/main.cpp",line="15",pending=["main.cpp:15"],times="0",original-location="main.cpp:15"}
-exec-run
^running
=thread-group-started,id="i1",pid="75620"
(gdb)
=thread-created,id="1",group-id="i1"
=thread-selected,id="1"
(gdb)
=shlibs-added,shlib-info=[num="2",name="dyld",dyld-addr="0x7fff5fc00000",reason="dyld",path="/usr/lib/dyld",loaded_addr="0x7fff5fc00000"]
(gdb)
=shlibs-added,shlib-info=[num="3",name="dyld",dyld-addr="0x7fff5fc00000",reason="dyld",path="/usr/lib/dyld",loaded_addr="0x7fff5fc00000"]
(gdb)
*running,thread-id="all"
(gdb)
(gdb)
=shlibs-added,shlib-info=[num="4",name="libc++.1.dylib",dyld-addr="0x7fff85dd0000",reason="dyld",path="/usr/lib/libc++.1.dylib",loaded_addr="0x7fff85dd0000"]
(gdb)
=shlibs-added,shlib-info=[num="5",name="libSystem.B.dylib",dyld-addr="0x7fff851ab000",reason="dyld",path="/usr/lib/libSystem.B.dylib",loaded_addr="0x7fff851ab000"]
(gdb)
=shlibs-added,shlib-info=[num="6",name="libc++abi.dylib",dyld-addr="0x7fff81be8000",reason="dyld",path="/usr/lib/libc++abi.dylib",loaded_addr="0x7fff81be8000"]
(gdb)
=shlibs-added,shlib-info=[num="7",name="libcache.dylib",dyld-addr="0x7fff8b975000",reason="dyld",path="/usr/lib/system/libcache.dylib",loaded_addr="0x7fff8b975000"]
(gdb)
=shlibs-added,shlib-info=[num="8",name="libcommonCrypto.dylib",dyld-addr="0x7fff85d14000",reason="dyld",path="/usr/lib/system/libcommonCrypto.dylib",loaded_addr="0x7fff85d14000"]
(gdb)
=shlibs-added,shlib-info=[num="9",name="libcompiler_rt.dylib",dyld-addr="0x7fff86154000",reason="dyld",path="/usr/lib/system/libcompiler_rt.dylib",loaded_addr="0x7fff86154000"]
(gdb)
=shlibs-added,shlib-info=[num="10",name="libcopyfile.dylib",dyld-addr="0x7fff81ac7000",reason="dyld",path="/usr/lib/system/libcopyfile.dylib",loaded_addr="0x7fff81ac7000"]
(gdb)
=shlibs-added,shlib-info=[num="11",name="libcorecrypto.dylib",dyld-addr="0x7fff87d5d000",reason="dyld",path="/usr/lib/system/libcorecrypto.dylib",loaded_addr="0x7fff87d5d000"]
(gdb)
=shlibs-added,shlib-info=[num="12",name="libdispatch.dylib",dyld-addr="0x7fff8ea8c000",reason="dyld",path="/usr/lib/system/libdispatch.dylib",loaded_addr="0x7fff8ea8c000"]
(gdb)
=shlibs-added,shlib-info=[num="13",name="libdyld.dylib",dyld-addr="0x7fff89087000",reason="dyld",path="/usr/lib/system/libdyld.dylib",loaded_addr="0x7fff89087000"]
(gdb)
=shlibs-added,shlib-info=[num="14",name="libkeymgr.dylib",dyld-addr="0x7fff8e818000",reason="dyld",path="/usr/lib/system/libkeymgr.dylib",loaded_addr="0x7fff8e818000"]
(gdb)
=shlibs-added,shlib-info=[num="15",name="liblaunch.dylib",dyld-addr="0x7fff84936000",reason="dyld",path="/usr/lib/system/liblaunch.dylib",loaded_addr="0x7fff84936000"]
(gdb)
=shlibs-added,shlib-info=[num="16",name="libmacho.dylib",dyld-addr="0x7fff8534e000",reason="dyld",path="/usr/lib/system/libmacho.dylib",loaded_addr="0x7fff8534e000"]
(gdb)
=shlibs-added,shlib-info=[num="17",name="libquarantine.dylib",dyld-addr="0x7fff90f97000",reason="dyld",path="/usr/lib/system/libquarantine.dylib",loaded_addr="0x7fff90f97000"]
(gdb)
=shlibs-added,shlib-info=[num="18",name="libremovefile.dylib",dyld-addr="0x7fff8ccb5000",reason="dyld",path="/usr/lib/system/libremovefile.dylib",loaded_addr="0x7fff8ccb5000"]
(gdb)
=shlibs-added,shlib-info=[num="19",name="libsystem_asl.dylib",dyld-addr="0x7fff8df67000",reason="dyld",path="/usr/lib/system/libsystem_asl.dylib",loaded_addr="0x7fff8df67000"]
(gdb)
=shlibs-added,shlib-info=[num="20",name="libsystem_blocks.dylib",dyld-addr="0x7fff8621c000",reason="dyld",path="/usr/lib/system/libsystem_blocks.dylib",loaded_addr="0x7fff8621c000"]
(gdb)
=shlibs-added,shlib-info=[num="21",name="libsystem_c.dylib",dyld-addr="0x7fff83c0f000",reason="dyld",path="/usr/lib/system/libsystem_c.dylib",loaded_addr="0x7fff83c0f000"]
(gdb)
=shlibs-added,shlib-info=[num="22",name="libsystem_configuration.dylib",dyld-addr="0x7fff8fd71000",reason="dyld",path="/usr/lib/system/libsystem_configuration.dylib",loaded_addr="0x7fff8fd71000"]
(gdb)
=shlibs-added,shlib-info=[num="23",name="libsystem_coreservices.dylib",dyld-addr="0x7fff8a028000",reason="dyld",path="/usr/lib/system/libsystem_coreservices.dylib",loaded_addr="0x7fff8a028000"]
(gdb)
=shlibs-added,shlib-info=[num="24",name="libsystem_coretls.dylib",dyld-addr="0x7fff90996000",reason="dyld",path="/usr/lib/system/libsystem_coretls.dylib",loaded_addr="0x7fff90996000"]
(gdb)
=shlibs-added,shlib-info=[num="25",name="libsystem_dnssd.dylib",dyld-addr="0x7fff8b71f000",reason="dyld",path="/usr/lib/system/libsystem_dnssd.dylib",loaded_addr="0x7fff8b71f000"]
(gdb)
=shlibs-added,shlib-info=[num="26",name="libsystem_info.dylib",dyld-addr="0x7fff8b9f2000",reason="dyld",path="/usr/lib/system/libsystem_info.dylib",loaded_addr="0x7fff8b9f2000"]
(gdb)
=shlibs-added,shlib-info=[num="27",name="libsystem_kernel.dylib",dyld-addr="0x7fff81ad0000",reason="dyld",path="/usr/lib/system/libsystem_kernel.dylib",loaded_addr="0x7fff81ad0000"]
(gdb)
=shlibs-added,shlib-info=[num="28",name="libsystem_m.dylib",dyld-addr="0x7fff84953000",reason="dyld",path="/usr/lib/system/libsystem_m.dylib",loaded_addr="0x7fff84953000"]
(gdb)
=shlibs-added,shlib-info=[num="29",name="libsystem_malloc.dylib",dyld-addr="0x7fff887bd000",reason="dyld",path="/usr/lib/system/libsystem_malloc.dylib",loaded_addr="0x7fff887bd000"]
(gdb)
=shlibs-added,shlib-info=[num="30",name="libsystem_network.dylib",dyld-addr="0x7fff88304000",reason="dyld",path="/usr/lib/system/libsystem_network.dylib",loaded_addr="0x7fff88304000"]
(gdb)
=shlibs-added,shlib-info=[num="31",name="libsystem_networkextension.dylib",dyld-addr="0x7fff82085000",reason="dyld",path="/usr/lib/system/libsystem_networkextension.dylib",loaded_addr="0x7fff82085000"]
(gdb)
=shlibs-added,shlib-info=[num="32",name="libsystem_notify.dylib",dyld-addr="0x7fff8eb69000",reason="dyld",path="/usr/lib/system/libsystem_notify.dylib",loaded_addr="0x7fff8eb69000"]
(gdb)
=shlibs-added,shlib-info=[num="33",name="libsystem_platform.dylib",dyld-addr="0x7fff89ac7000",reason="dyld",path="/usr/lib/system/libsystem_platform.dylib",loaded_addr="0x7fff89ac7000"]
(gdb)
=shlibs-added,shlib-info=[num="34",name="libsystem_pthread.dylib",dyld-addr="0x7fff83ff8000",reason="dyld",path="/usr/lib/system/libsystem_pthread.dylib",loaded_addr="0x7fff83ff8000"]
(gdb)
=shlibs-added,shlib-info=[num="35",name="libsystem_sandbox.dylib",dyld-addr="0x7fff89084000",reason="dyld",path="/usr/lib/system/libsystem_sandbox.dylib",loaded_addr="0x7fff89084000"]
(gdb)
=shlibs-added,shlib-info=[num="36",name="libsystem_secinit.dylib",dyld-addr="0x7fff8e816000",reason="dyld",path="/usr/lib/system/libsystem_secinit.dylib",loaded_addr="0x7fff8e816000"]
(gdb)
=shlibs-added,shlib-info=[num="37",name="libsystem_stats.dylib",dyld-addr="0x7fff89eaf000",reason="dyld",path="/usr/lib/system/libsystem_stats.dylib",loaded_addr="0x7fff89eaf000"]
(gdb)
=shlibs-added,shlib-info=[num="38",name="libsystem_trace.dylib",dyld-addr="0x7fff8ead4000",reason="dyld",path="/usr/lib/system/libsystem_trace.dylib",loaded_addr="0x7fff8ead4000"]
(gdb)
=shlibs-added,shlib-info=[num="39",name="libunc.dylib",dyld-addr="0x7fff8ab27000",reason="dyld",path="/usr/lib/system/libunc.dylib",loaded_addr="0x7fff8ab27000"]
(gdb)
=shlibs-added,shlib-info=[num="40",name="libunwind.dylib",dyld-addr="0x7fff85cf3000",reason="dyld",path="/usr/lib/system/libunwind.dylib",loaded_addr="0x7fff85cf3000"]
(gdb)
=shlibs-added,shlib-info=[num="41",name="libxpc.dylib",dyld-addr="0x7fff88896000",reason="dyld",path="/usr/lib/system/libxpc.dylib",loaded_addr="0x7fff88896000"]
(gdb)
=shlibs-added,shlib-info=[num="42",name="libobjc.A.dylib",dyld-addr="0x7fff84f13000",reason="dyld",path="/usr/lib/libobjc.A.dylib",loaded_addr="0x7fff84f13000"]
(gdb)
=shlibs-added,shlib-info=[num="43",name="libauto.dylib",dyld-addr="0x7fff85d89000",reason="dyld",path="/usr/lib/libauto.dylib",loaded_addr="0x7fff85d89000"]
(gdb)
=shlibs-added,shlib-info=[num="44",name="libDiagnosticMessagesClient.dylib",dyld-addr="0x7fff822e1000",reason="dyld",path="/usr/lib/libDiagnosticMessagesClient.dylib",loaded_addr="0x7fff822e1000"]
```
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000100000f4d",func="main",file="main.cpp",fullname="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/main.cpp",line="15",pending=["main.cpp:15"],times="0",original-location="main.cpp:15"}
```
(gdb)
=shlibs-added,shlib-info=[num="45",name="a.out",dyld-addr="0x100000000",reason="dyld",path="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/a.out",loaded_addr="0x100000000",dsym-objpath="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/a.out.dSYM/Contents/Resources/DWARF/a.out"]
=shlibs-added,shlib-info=[num="46",name="libc++.1.dylib",dyld-addr="0x7fff85dd0000",reason="dyld",path="/usr/lib/libc++.1.dylib",loaded_addr="0x7fff85dd0000"]
=shlibs-added,shlib-info=[num="47",name="libSystem.B.dylib",dyld-addr="0x7fff851ab000",reason="dyld",path="/usr/lib/libSystem.B.dylib",loaded_addr="0x7fff851ab000"]
=shlibs-added,shlib-info=[num="48",name="libc++abi.dylib",dyld-addr="0x7fff81be8000",reason="dyld",path="/usr/lib/libc++abi.dylib",loaded_addr="0x7fff81be8000"]
=shlibs-added,shlib-info=[num="49",name="libcache.dylib",dyld-addr="0x7fff8b975000",reason="dyld",path="/usr/lib/system/libcache.dylib",loaded_addr="0x7fff8b975000"]
=shlibs-added,shlib-info=[num="50",name="libcommonCrypto.dylib",dyld-addr="0x7fff85d14000",reason="dyld",path="/usr/lib/system/libcommonCrypto.dylib",loaded_addr="0x7fff85d14000"]
=shlibs-added,shlib-info=[num="51",name="libcompiler_rt.dylib",dyld-addr="0x7fff86154000",reason="dyld",path="/usr/lib/system/libcompiler_rt.dylib",loaded_addr="0x7fff86154000"]
=shlibs-added,shlib-info=[num="52",name="libcopyfile.dylib",dyld-addr="0x7fff81ac7000",reason="dyld",path="/usr/lib/system/libcopyfile.dylib",loaded_addr="0x7fff81ac7000"]
=shlibs-added,shlib-info=[num="53",name="libcorecrypto.dylib",dyld-addr="0x7fff87d5d000",reason="dyld",path="/usr/lib/system/libcorecrypto.dylib",loaded_addr="0x7fff87d5d000"]
=shlibs-added,shlib-info=[num="54",name="libdispatch.dylib",dyld-addr="0x7fff8ea8c000",reason="dyld",path="/usr/lib/system/libdispatch.dylib",loaded_addr="0x7fff8ea8c000"]
=shlibs-added,shlib-info=[num="55",name="libdyld.dylib",dyld-addr="0x7fff89087000",reason="dyld",path="/usr/lib/system/libdyld.dylib",loaded_addr="0x7fff89087000"]
=shlibs-added,shlib-info=[num="56",name="libkeymgr.dylib",dyld-addr="0x7fff8e818000",reason="dyld",path="/usr/lib/system/libkeymgr.dylib",loaded_addr="0x7fff8e818000"]
=shlibs-added,shlib-info=[num="57",name="liblaunch.dylib",dyld-addr="0x7fff84936000",reason="dyld",path="/usr/lib/system/liblaunch.dylib",loaded_addr="0x7fff84936000"]
=shlibs-added,shlib-info=[num="58",name="libmacho.dylib",dyld-addr="0x7fff8534e000",reason="dyld",path="/usr/lib/system/libmacho.dylib",loaded_addr="0x7fff8534e000"]
=shlibs-added,shlib-info=[num="59",name="libquarantine.dylib",dyld-addr="0x7fff90f97000",reason="dyld",path="/usr/lib/system/libquarantine.dylib",loaded_addr="0x7fff90f97000"]
=shlibs-added,shlib-info=[num="60",name="libremovefile.dylib",dyld-addr="0x7fff8ccb5000",reason="dyld",path="/usr/lib/system/libremovefile.dylib",loaded_addr="0x7fff8ccb5000"]
=shlibs-added,shlib-info=[num="61",name="libsystem_asl.dylib",dyld-addr="0x7fff8df67000",reason="dyld",path="/usr/lib/system/libsystem_asl.dylib",loaded_addr="0x7fff8df67000"]
=shlibs-added,shlib-info=[num="62",name="libsystem_blocks.dylib",dyld-addr="0x7fff8621c000",reason="dyld",path="/usr/lib/system/libsystem_blocks.dylib",loaded_addr="0x7fff8621c000"]
=shlibs-added,shlib-info=[num="63",name="libsystem_c.dylib",dyld-addr="0x7fff83c0f000",reason="dyld",path="/usr/lib/system/libsystem_c.dylib",loaded_addr="0x7fff83c0f000"]
=shlibs-added,shlib-info=[num="64",name="libsystem_configuration.dylib",dyld-addr="0x7fff8fd71000",reason="dyld",path="/usr/lib/system/libsystem_configuration.dylib",loaded_addr="0x7fff8fd71000"]
=shlibs-added,shlib-info=[num="65",name="libsystem_coreservices.dylib",dyld-addr="0x7fff8a028000",reason="dyld",path="/usr/lib/system/libsystem_coreservices.dylib",loaded_addr="0x7fff8a028000"]
=shlibs-added,shlib-info=[num="66",name="libsystem_coretls.dylib",dyld-addr="0x7fff90996000",reason="dyld",path="/usr/lib/system/libsystem_coretls.dylib",loaded_addr="0x7fff90996000"]
=shlibs-added,shlib-info=[num="67",name="libsystem_dnssd.dylib",dyld-addr="0x7fff8b71f000",reason="dyld",path="/usr/lib/system/libsystem_dnssd.dylib",loaded_addr="0x7fff8b71f000"]
=shlibs-added,shlib-info=[num="68",name="libsystem_info.dylib",dyld-addr="0x7fff8b9f2000",reason="dyld",path="/usr/lib/system/libsystem_info.dylib",loaded_addr="0x7fff8b9f2000"]
=shlibs-added,shlib-info=[num="69",name="libsystem_kernel.dylib",dyld-addr="0x7fff81ad0000",reason="dyld",path="/usr/lib/system/libsystem_kernel.dylib",loaded_addr="0x7fff81ad0000"]
=shlibs-added,shlib-info=[num="70",name="libsystem_m.dylib",dyld-addr="0x7fff84953000",reason="dyld",path="/usr/lib/system/libsystem_m.dylib",loaded_addr="0x7fff84953000"]
=shlibs-added,shlib-info=[num="71",name="libsystem_malloc.dylib",dyld-addr="0x7fff887bd000",reason="dyld",path="/usr/lib/system/libsystem_malloc.dylib",loaded_addr="0x7fff887bd000"]
=shlibs-added,shlib-info=[num="72",name="libsystem_network.dylib",dyld-addr="0x7fff88304000",reason="dyld",path="/usr/lib/system/libsystem_network.dylib",loaded_addr="0x7fff88304000"]
=shlibs-added,shlib-info=[num="73",name="libsystem_networkextension.dylib",dyld-addr="0x7fff82085000",reason="dyld",path="/usr/lib/system/libsystem_networkextension.dylib",loaded_addr="0x7fff82085000"]
=shlibs-added,shlib-info=[num="74",name="libsystem_notify.dylib",dyld-addr="0x7fff8eb69000",reason="dyld",path="/usr/lib/system/libsystem_notify.dylib",loaded_addr="0x7fff8eb69000"]
=shlibs-added,shlib-info=[num="75",name="libsystem_platform.dylib",dyld-addr="0x7fff89ac7000",reason="dyld",path="/usr/lib/system/libsystem_platform.dylib",loaded_addr="0x7fff89ac7000"]
=shlibs-added,shlib-info=[num="76",name="libsystem_pthread.dylib",dyld-addr="0x7fff83ff8000",reason="dyld",path="/usr/lib/system/libsystem_pthread.dylib",loaded_addr="0x7fff83ff8000"]
=shlibs-added,shlib-info=[num="77",name="libsystem_sandbox.dylib",dyld-addr="0x7fff89084000",reason="dyld",path="/usr/lib/system/libsystem_sandbox.dylib",loaded_addr="0x7fff89084000"]
=shlibs-added,shlib-info=[num="78",name="libsystem_secinit.dylib",dyld-addr="0x7fff8e816000",reason="dyld",path="/usr/lib/system/libsystem_secinit.dylib",loaded_addr="0x7fff8e816000"]
=shlibs-added,shlib-info=[num="79",name="libsystem_stats.dylib",dyld-addr="0x7fff89eaf000",reason="dyld",path="/usr/lib/system/libsystem_stats.dylib",loaded_addr="0x7fff89eaf000"]
=shlibs-added,shlib-info=[num="80",name="libsystem_trace.dylib",dyld-addr="0x7fff8ead4000",reason="dyld",path="/usr/lib/system/libsystem_trace.dylib",loaded_addr="0x7fff8ead4000"]
=shlibs-added,shlib-info=[num="81",name="libunc.dylib",dyld-addr="0x7fff8ab27000",reason="dyld",path="/usr/lib/system/libunc.dylib",loaded_addr="0x7fff8ab27000"]
=shlibs-added,shlib-info=[num="82",name="libunwind.dylib",dyld-addr="0x7fff85cf3000",reason="dyld",path="/usr/lib/system/libunwind.dylib",loaded_addr="0x7fff85cf3000"]
=shlibs-added,shlib-info=[num="83",name="libxpc.dylib",dyld-addr="0x7fff88896000",reason="dyld",path="/usr/lib/system/libxpc.dylib",loaded_addr="0x7fff88896000"]
=shlibs-added,shlib-info=[num="84",name="libobjc.A.dylib",dyld-addr="0x7fff84f13000",reason="dyld",path="/usr/lib/libobjc.A.dylib",loaded_addr="0x7fff84f13000"]
=shlibs-added,shlib-info=[num="85",name="libauto.dylib",dyld-addr="0x7fff85d89000",reason="dyld",path="/usr/lib/libauto.dylib",loaded_addr="0x7fff85d89000"]
=shlibs-added,shlib-info=[num="86",name="libDiagnosticMessagesClient.dylib",dyld-addr="0x7fff822e1000",reason="dyld",path="/usr/lib/libDiagnosticMessagesClient.dylib",loaded_addr="0x7fff822e1000"]
(gdb)
*stopped,reason="breakpoint-hit",disp="del",bkptno="1",frame={addr="0x0000000100000f4d",func="main",args=[{name="argc",value="1"},{name="argv",value="0x00007fff5fbffed8"}],file="main.cpp",fullname="/Users/chuckr/llama/llvm/tools/lldb/test/tools/lldb-mi/main.cpp",line="15"},thread-id="1",stopped-threads="all"
(gdb)
```

Reviewers: abidh, clayborg, ChuckR, jingham

Subscribers: ki.stfu, paulmaybee, lldb-commits

Differential Revision: http://reviews.llvm.org/D8847

llvm-svn: 234483
2015-04-09 12:55:13 +00:00

753 lines
22 KiB
C++

//===-- BreakpointLocation.cpp ----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/lldb-python.h"
// C Includes
// C++ Includes
#include <string>
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/BreakpointID.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Expression/ClangUserExpression.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadSpec.h"
using namespace lldb;
using namespace lldb_private;
BreakpointLocation::BreakpointLocation
(
break_id_t loc_id,
Breakpoint &owner,
const Address &addr,
lldb::tid_t tid,
bool hardware,
bool check_for_resolver
) :
StoppointLocation (loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()), hardware),
m_being_created(true),
m_should_resolve_indirect_functions (false),
m_is_reexported (false),
m_is_indirect (false),
m_address (addr),
m_owner (owner),
m_options_ap (),
m_bp_site_sp (),
m_condition_mutex ()
{
if (check_for_resolver)
{
Symbol *symbol = m_address.CalculateSymbolContextSymbol();
if (symbol && symbol->IsIndirect())
{
SetShouldResolveIndirectFunctions (true);
}
}
SetThreadID (tid);
m_being_created = false;
}
BreakpointLocation::~BreakpointLocation()
{
ClearBreakpointSite();
}
lldb::addr_t
BreakpointLocation::GetLoadAddress () const
{
return m_address.GetOpcodeLoadAddress (&m_owner.GetTarget());
}
Address &
BreakpointLocation::GetAddress ()
{
return m_address;
}
Breakpoint &
BreakpointLocation::GetBreakpoint ()
{
return m_owner;
}
bool
BreakpointLocation::IsEnabled () const
{
if (!m_owner.IsEnabled())
return false;
else if (m_options_ap.get() != NULL)
return m_options_ap->IsEnabled();
else
return true;
}
void
BreakpointLocation::SetEnabled (bool enabled)
{
GetLocationOptions()->SetEnabled(enabled);
if (enabled)
{
ResolveBreakpointSite();
}
else
{
ClearBreakpointSite();
}
SendBreakpointLocationChangedEvent (enabled ? eBreakpointEventTypeEnabled : eBreakpointEventTypeDisabled);
}
void
BreakpointLocation::SetThreadID (lldb::tid_t thread_id)
{
if (thread_id != LLDB_INVALID_THREAD_ID)
GetLocationOptions()->SetThreadID(thread_id);
else
{
// If we're resetting this to an invalid thread id, then
// don't make an options pointer just to do that.
if (m_options_ap.get() != NULL)
m_options_ap->SetThreadID (thread_id);
}
SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
}
lldb::tid_t
BreakpointLocation::GetThreadID ()
{
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID();
else
return LLDB_INVALID_THREAD_ID;
}
void
BreakpointLocation::SetThreadIndex (uint32_t index)
{
if (index != 0)
GetLocationOptions()->GetThreadSpec()->SetIndex(index);
else
{
// If we're resetting this to an invalid thread id, then
// don't make an options pointer just to do that.
if (m_options_ap.get() != NULL)
m_options_ap->GetThreadSpec()->SetIndex(index);
}
SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
}
uint32_t
BreakpointLocation::GetThreadIndex() const
{
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetIndex();
else
return 0;
}
void
BreakpointLocation::SetThreadName (const char *thread_name)
{
if (thread_name != NULL)
GetLocationOptions()->GetThreadSpec()->SetName(thread_name);
else
{
// If we're resetting this to an invalid thread id, then
// don't make an options pointer just to do that.
if (m_options_ap.get() != NULL)
m_options_ap->GetThreadSpec()->SetName(thread_name);
}
SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
}
const char *
BreakpointLocation::GetThreadName () const
{
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetName();
else
return NULL;
}
void
BreakpointLocation::SetQueueName (const char *queue_name)
{
if (queue_name != NULL)
GetLocationOptions()->GetThreadSpec()->SetQueueName(queue_name);
else
{
// If we're resetting this to an invalid thread id, then
// don't make an options pointer just to do that.
if (m_options_ap.get() != NULL)
m_options_ap->GetThreadSpec()->SetQueueName(queue_name);
}
SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
}
const char *
BreakpointLocation::GetQueueName () const
{
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetQueueName();
else
return NULL;
}
bool
BreakpointLocation::InvokeCallback (StoppointCallbackContext *context)
{
if (m_options_ap.get() != NULL && m_options_ap->HasCallback())
return m_options_ap->InvokeCallback (context, m_owner.GetID(), GetID());
else
return m_owner.InvokeCallback (context, GetID());
}
void
BreakpointLocation::SetCallback (BreakpointHitCallback callback, void *baton,
bool is_synchronous)
{
// The default "Baton" class will keep a copy of "baton" and won't free
// or delete it when it goes goes out of scope.
GetLocationOptions()->SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous);
SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged);
}
void
BreakpointLocation::SetCallback (BreakpointHitCallback callback, const BatonSP &baton_sp,
bool is_synchronous)
{
GetLocationOptions()->SetCallback (callback, baton_sp, is_synchronous);
SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged);
}
void
BreakpointLocation::ClearCallback ()
{
GetLocationOptions()->ClearCallback();
}
void
BreakpointLocation::SetCondition (const char *condition)
{
GetLocationOptions()->SetCondition (condition);
SendBreakpointLocationChangedEvent (eBreakpointEventTypeConditionChanged);
}
const char *
BreakpointLocation::GetConditionText (size_t *hash) const
{
return GetOptionsNoCreate()->GetConditionText(hash);
}
bool
BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
Mutex::Locker evaluation_locker(m_condition_mutex);
size_t condition_hash;
const char *condition_text = GetConditionText(&condition_hash);
if (!condition_text)
{
m_user_expression_sp.reset();
return false;
}
if (condition_hash != m_condition_hash ||
!m_user_expression_sp ||
!m_user_expression_sp->MatchesContext(exe_ctx))
{
m_user_expression_sp.reset(new ClangUserExpression(condition_text,
NULL,
lldb::eLanguageTypeUnknown,
ClangUserExpression::eResultTypeAny));
StreamString errors;
if (!m_user_expression_sp->Parse(errors,
exe_ctx,
eExecutionPolicyOnlyWhenNeeded,
true,
false))
{
error.SetErrorStringWithFormat("Couldn't parse conditional expression:\n%s",
errors.GetData());
m_user_expression_sp.reset();
return false;
}
m_condition_hash = condition_hash;
}
// We need to make sure the user sees any parse errors in their condition, so we'll hook the
// constructor errors up to the debugger's Async I/O.
ValueObjectSP result_value_sp;
EvaluateExpressionOptions options;
options.SetUnwindOnError(true);
options.SetIgnoreBreakpoints(true);
options.SetTryAllThreads(true);
Error expr_error;
StreamString execution_errors;
ClangExpressionVariableSP result_variable_sp;
ExpressionResults result_code =
m_user_expression_sp->Execute(execution_errors,
exe_ctx,
options,
m_user_expression_sp,
result_variable_sp);
bool ret;
if (result_code == eExpressionCompleted)
{
if (!result_variable_sp)
{
error.SetErrorString("Expression did not return a result");
return false;
}
result_value_sp = result_variable_sp->GetValueObject();
if (result_value_sp)
{
Scalar scalar_value;
if (result_value_sp->ResolveValue (scalar_value))
{
if (scalar_value.ULongLong(1) == 0)
ret = false;
else
ret = true;
if (log)
log->Printf("Condition successfully evaluated, result is %s.\n",
ret ? "true" : "false");
}
else
{
ret = false;
error.SetErrorString("Failed to get an integer result from the expression");
}
}
else
{
ret = false;
error.SetErrorString("Failed to get any result from the expression");
}
}
else
{
ret = false;
error.SetErrorStringWithFormat("Couldn't execute expression:\n%s", execution_errors.GetData());
}
return ret;
}
uint32_t
BreakpointLocation::GetIgnoreCount ()
{
return GetOptionsNoCreate()->GetIgnoreCount();
}
void
BreakpointLocation::SetIgnoreCount (uint32_t n)
{
GetLocationOptions()->SetIgnoreCount(n);
SendBreakpointLocationChangedEvent (eBreakpointEventTypeIgnoreChanged);
}
void
BreakpointLocation::DecrementIgnoreCount()
{
if (m_options_ap.get() != NULL)
{
uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
if (loc_ignore != 0)
m_options_ap->SetIgnoreCount(loc_ignore - 1);
}
}
bool
BreakpointLocation::IgnoreCountShouldStop()
{
if (m_options_ap.get() != NULL)
{
uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
if (loc_ignore != 0)
{
m_owner.DecrementIgnoreCount();
DecrementIgnoreCount(); // Have to decrement our owners' ignore count, since it won't get a
// chance to.
return false;
}
}
return true;
}
const BreakpointOptions *
BreakpointLocation::GetOptionsNoCreate () const
{
if (m_options_ap.get() != NULL)
return m_options_ap.get();
else
return m_owner.GetOptions ();
}
BreakpointOptions *
BreakpointLocation::GetLocationOptions ()
{
// If we make the copy we don't copy the callbacks because that is potentially
// expensive and we don't want to do that for the simple case where someone is
// just disabling the location.
if (m_options_ap.get() == NULL)
m_options_ap.reset(BreakpointOptions::CopyOptionsNoCallback(*m_owner.GetOptions ()));
return m_options_ap.get();
}
bool
BreakpointLocation::ValidForThisThread (Thread *thread)
{
return thread->MatchesSpec(GetOptionsNoCreate()->GetThreadSpecNoCreate());
}
// RETURNS - true if we should stop at this breakpoint, false if we
// should continue. Note, we don't check the thread spec for the breakpoint
// here, since if the breakpoint is not for this thread, then the event won't
// even get reported, so the check is redundant.
bool
BreakpointLocation::ShouldStop (StoppointCallbackContext *context)
{
bool should_stop = true;
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
// Do this first, if a location is disabled, it shouldn't increment its hit count.
if (!IsEnabled())
return false;
if (!IgnoreCountShouldStop())
return false;
if (!m_owner.IgnoreCountShouldStop())
return false;
// We only run synchronous callbacks in ShouldStop:
context->is_synchronous = true;
should_stop = InvokeCallback (context);
if (log)
{
StreamString s;
GetDescription (&s, lldb::eDescriptionLevelVerbose);
log->Printf ("Hit breakpoint location: %s, %s.\n", s.GetData(), should_stop ? "stopping" : "continuing");
}
return should_stop;
}
void
BreakpointLocation::BumpHitCount()
{
if (IsEnabled())
{
// Step our hit count, and also step the hit count of the owner.
IncrementHitCount();
m_owner.IncrementHitCount();
}
}
void
BreakpointLocation::UndoBumpHitCount()
{
if (IsEnabled())
{
// Step our hit count, and also step the hit count of the owner.
DecrementHitCount();
m_owner.DecrementHitCount();
}
}
bool
BreakpointLocation::IsResolved () const
{
return m_bp_site_sp.get() != NULL;
}
lldb::BreakpointSiteSP
BreakpointLocation::GetBreakpointSite() const
{
return m_bp_site_sp;
}
bool
BreakpointLocation::ResolveBreakpointSite ()
{
if (m_bp_site_sp)
return true;
Process *process = m_owner.GetTarget().GetProcessSP().get();
if (process == NULL)
return false;
lldb::break_id_t new_id = process->CreateBreakpointSite (shared_from_this(), m_owner.IsHardware());
if (new_id == LLDB_INVALID_BREAK_ID)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
if (log)
log->Warning ("Tried to add breakpoint site at 0x%" PRIx64 " but it was already present.\n",
m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()));
return false;
}
return true;
}
bool
BreakpointLocation::SetBreakpointSite (BreakpointSiteSP& bp_site_sp)
{
m_bp_site_sp = bp_site_sp;
SendBreakpointLocationChangedEvent (eBreakpointEventTypeLocationsResolved);
return true;
}
bool
BreakpointLocation::ClearBreakpointSite ()
{
if (m_bp_site_sp.get())
{
ProcessSP process_sp(m_owner.GetTarget().GetProcessSP());
// If the process exists, get it to remove the owner, it will remove the physical implementation
// of the breakpoint as well if there are no more owners. Otherwise just remove this owner.
if (process_sp)
process_sp->RemoveOwnerFromBreakpointSite (GetBreakpoint().GetID(),
GetID(), m_bp_site_sp);
else
m_bp_site_sp->RemoveOwner(GetBreakpoint().GetID(), GetID());
m_bp_site_sp.reset();
return true;
}
return false;
}
void
BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
{
SymbolContext sc;
// If the description level is "initial" then the breakpoint is printing out our initial state,
// and we should let it decide how it wants to print our label.
if (level != eDescriptionLevelInitial)
{
s->Indent();
BreakpointID::GetCanonicalReference(s, m_owner.GetID(), GetID());
}
if (level == lldb::eDescriptionLevelBrief)
return;
if (level != eDescriptionLevelInitial)
s->PutCString(": ");
if (level == lldb::eDescriptionLevelVerbose)
s->IndentMore();
if (m_address.IsSectionOffset())
{
m_address.CalculateSymbolContext(&sc);
if (level == lldb::eDescriptionLevelFull || level == eDescriptionLevelInitial)
{
if (IsReExported())
s->PutCString ("re-exported target = ");
else
s->PutCString("where = ");
sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, false, true, false, true, true);
}
else
{
if (sc.module_sp)
{
s->EOL();
s->Indent("module = ");
sc.module_sp->GetFileSpec().Dump (s);
}
if (sc.comp_unit != NULL)
{
s->EOL();
s->Indent("compile unit = ");
static_cast<FileSpec*>(sc.comp_unit)->GetFilename().Dump (s);
if (sc.function != NULL)
{
s->EOL();
s->Indent("function = ");
s->PutCString (sc.function->GetMangled().GetName().AsCString("<unknown>"));
}
if (sc.line_entry.line > 0)
{
s->EOL();
s->Indent("location = ");
sc.line_entry.DumpStopContext (s, true);
}
}
else
{
// If we don't have a comp unit, see if we have a symbol we can print.
if (sc.symbol)
{
s->EOL();
if (IsReExported())
s->Indent ("re-exported target = ");
else
s->Indent("symbol = ");
s->PutCString(sc.symbol->GetMangled().GetName().AsCString("<unknown>"));
}
}
}
}
if (level == lldb::eDescriptionLevelVerbose)
{
s->EOL();
s->Indent();
}
if (m_address.IsSectionOffset() && (level == eDescriptionLevelFull || level == eDescriptionLevelInitial))
s->Printf (", ");
s->Printf ("address = ");
ExecutionContextScope *exe_scope = NULL;
Target *target = &m_owner.GetTarget();
if (target)
exe_scope = target->GetProcessSP().get();
if (exe_scope == NULL)
exe_scope = target;
if (level == eDescriptionLevelInitial)
m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
else
m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress);
if (IsIndirect() && m_bp_site_sp)
{
Address resolved_address;
resolved_address.SetLoadAddress(m_bp_site_sp->GetLoadAddress(), target);
Symbol *resolved_symbol = resolved_address.CalculateSymbolContextSymbol();
if (resolved_symbol)
{
if (level == eDescriptionLevelFull || level == eDescriptionLevelInitial)
s->Printf (", ");
else if (level == lldb::eDescriptionLevelVerbose)
{
s->EOL();
s->Indent();
}
s->Printf ("indirect target = %s", resolved_symbol->GetName().GetCString());
}
}
if (level == lldb::eDescriptionLevelVerbose)
{
s->EOL();
s->Indent();
s->Printf("resolved = %s\n", IsResolved() ? "true" : "false");
s->Indent();
s->Printf ("hit count = %-4u\n", GetHitCount());
if (m_options_ap.get())
{
s->Indent();
m_options_ap->GetDescription (s, level);
s->EOL();
}
s->IndentLess();
}
else if (level != eDescriptionLevelInitial)
{
s->Printf(", %sresolved, hit count = %u ",
(IsResolved() ? "" : "un"),
GetHitCount());
if (m_options_ap.get())
{
m_options_ap->GetDescription (s, level);
}
}
}
void
BreakpointLocation::Dump(Stream *s) const
{
if (s == NULL)
return;
s->Printf("BreakpointLocation %u: tid = %4.4" PRIx64 " load addr = 0x%8.8" PRIx64 " state = %s type = %s breakpoint "
"hw_index = %i hit_count = %-4u ignore_count = %-4u",
GetID(),
GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(),
(uint64_t) m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()),
(m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled()) ? "enabled " : "disabled",
IsHardware() ? "hardware" : "software",
GetHardwareIndex(),
GetHitCount(),
GetOptionsNoCreate()->GetIgnoreCount());
}
void
BreakpointLocation::SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind)
{
if (!m_being_created
&& !m_owner.IsInternal()
&& m_owner.GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
{
Breakpoint::BreakpointEventData *data = new Breakpoint::BreakpointEventData (eventKind,
m_owner.shared_from_this());
data->GetBreakpointLocationCollection().Add (shared_from_this());
m_owner.GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data);
}
}
void
BreakpointLocation::SwapLocation (BreakpointLocationSP swap_from)
{
m_address = swap_from->m_address;
m_should_resolve_indirect_functions = swap_from->m_should_resolve_indirect_functions;
m_is_reexported = swap_from->m_is_reexported;
m_is_indirect = swap_from->m_is_indirect;
m_user_expression_sp.reset();
}