180814287SRaphael Isemann //===-- BreakpointName.cpp ------------------------------------------------===//
2b842f2ecSJim Ingham //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b842f2ecSJim Ingham //
7b842f2ecSJim Ingham //===----------------------------------------------------------------------===//
8b842f2ecSJim Ingham
9b842f2ecSJim Ingham #include "llvm/Support/Casting.h"
10b842f2ecSJim Ingham
11b842f2ecSJim Ingham #include "lldb/Breakpoint/Breakpoint.h"
12b842f2ecSJim Ingham #include "lldb/Breakpoint/BreakpointOptions.h"
13b842f2ecSJim Ingham #include "lldb/Breakpoint/BreakpointLocationCollection.h"
14b842f2ecSJim Ingham #include "lldb/Breakpoint/BreakpointResolver.h"
15b842f2ecSJim Ingham #include "lldb/Breakpoint/BreakpointResolverFileLine.h"
16b842f2ecSJim Ingham #include "lldb/Utility/Log.h"
17b842f2ecSJim Ingham #include "lldb/Utility/Stream.h"
18b842f2ecSJim Ingham #include "lldb/Utility/StreamString.h"
19b842f2ecSJim Ingham
20b842f2ecSJim Ingham using namespace lldb;
21b842f2ecSJim Ingham using namespace lldb_private;
22b842f2ecSJim Ingham
23b842f2ecSJim Ingham const Flags::ValueType BreakpointName::Permissions::permissions_mask
24b842f2ecSJim Ingham [BreakpointName::Permissions::PermissionKinds::allPerms + 1] = {
25b842f2ecSJim Ingham (1u << 0),
26b842f2ecSJim Ingham (1u << 1),
27b842f2ecSJim Ingham (1u << 2),
28b842f2ecSJim Ingham (0x5u)
29b842f2ecSJim Ingham };
30b842f2ecSJim Ingham
BreakpointName(ConstString name,const Breakpoint & bkpt,const char * help)310e4c4821SAdrian Prantl BreakpointName::BreakpointName(ConstString name, const Breakpoint &bkpt,
32b842f2ecSJim Ingham const char *help) :
33b842f2ecSJim Ingham m_name(name), m_options(bkpt.GetOptions())
34b842f2ecSJim Ingham {
35b842f2ecSJim Ingham SetHelp(help);
36b842f2ecSJim Ingham }
37b842f2ecSJim Ingham
GetDescription(Stream * s,lldb::DescriptionLevel level)38b842f2ecSJim Ingham bool BreakpointName::Permissions::GetDescription(Stream *s,
39b842f2ecSJim Ingham lldb::DescriptionLevel level) {
40b842f2ecSJim Ingham if (!AnySet())
41b842f2ecSJim Ingham return false;
42b842f2ecSJim Ingham s->IndentMore();
43b842f2ecSJim Ingham s->Indent();
44b842f2ecSJim Ingham if (IsSet(listPerm))
45b842f2ecSJim Ingham s->Printf("list: %s", GetAllowList() ? "allowed" : "disallowed");
46b842f2ecSJim Ingham
47b842f2ecSJim Ingham if (IsSet(disablePerm))
48b842f2ecSJim Ingham s->Printf("disable: %s", GetAllowDisable() ? "allowed" : "disallowed");
49b842f2ecSJim Ingham
50b842f2ecSJim Ingham if (IsSet(deletePerm))
51b842f2ecSJim Ingham s->Printf("delete: %s", GetAllowDelete() ? "allowed" : "disallowed");
52b842f2ecSJim Ingham s->IndentLess();
53b842f2ecSJim Ingham return true;
54b842f2ecSJim Ingham }
55b842f2ecSJim Ingham
GetDescription(Stream * s,lldb::DescriptionLevel level)56b842f2ecSJim Ingham bool BreakpointName::GetDescription(Stream *s, lldb::DescriptionLevel level) {
57b842f2ecSJim Ingham bool printed_any = false;
58e9632ebaSJim Ingham if (!m_help.empty())
59e9632ebaSJim Ingham s->Printf("Help: %s\n", m_help.c_str());
60e9632ebaSJim Ingham
61b842f2ecSJim Ingham if (GetOptions().AnySet())
62b842f2ecSJim Ingham {
63b842f2ecSJim Ingham s->PutCString("Options: \n");
64b842f2ecSJim Ingham s->IndentMore();
65b842f2ecSJim Ingham s->Indent();
66b842f2ecSJim Ingham GetOptions().GetDescription(s, level);
67b842f2ecSJim Ingham printed_any = true;
68b842f2ecSJim Ingham s->IndentLess();
69b842f2ecSJim Ingham }
70b842f2ecSJim Ingham if (GetPermissions().AnySet())
71b842f2ecSJim Ingham {
72b842f2ecSJim Ingham s->PutCString("Permissions: \n");
73b842f2ecSJim Ingham s->IndentMore();
74b842f2ecSJim Ingham s->Indent();
75b842f2ecSJim Ingham GetPermissions().GetDescription(s, level);
76b842f2ecSJim Ingham printed_any = true;
77b842f2ecSJim Ingham s->IndentLess();
78b842f2ecSJim Ingham }
79b842f2ecSJim Ingham return printed_any;
80b842f2ecSJim Ingham }
81b842f2ecSJim Ingham
ConfigureBreakpoint(lldb::BreakpointSP bp_sp)82b842f2ecSJim Ingham void BreakpointName::ConfigureBreakpoint(lldb::BreakpointSP bp_sp)
83b842f2ecSJim Ingham {
84*cfb96d84SJim Ingham bp_sp->GetOptions().CopyOverSetOptions(GetOptions());
85b842f2ecSJim Ingham bp_sp->GetPermissions().MergeInto(GetPermissions());
86b842f2ecSJim Ingham }
87