summaryrefslogtreecommitdiff
path: root/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp
blob: cc902b7f7ad52ed9e2174bcc891548852620bc8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//===-- PlatformKalimba.cpp ---------------------------------------*- C++
//-*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "PlatformKalimba.h"
#include "lldb/Host/Config.h"

#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"

using namespace lldb;
using namespace lldb_private;

static uint32_t g_initialize_count = 0;

PlatformSP PlatformKalimba::CreateInstance(bool force, const ArchSpec *arch) {
  bool create = force;
  if (!create && arch && arch->IsValid()) {
    const llvm::Triple &triple = arch->GetTriple();
    switch (triple.getVendor()) {
    case llvm::Triple::CSR:
      create = true;
      break;

    default:
      break;
    }
  }
  if (create)
    return PlatformSP(new PlatformKalimba(false));
  return PlatformSP();
}

lldb_private::ConstString
PlatformKalimba::GetPluginNameStatic(bool /*is_host*/) {
  static ConstString g_remote_name("kalimba");
  return g_remote_name;
}

const char *PlatformKalimba::GetPluginDescriptionStatic(bool /*is_host*/) {
  return "Kalimba user platform plug-in.";
}

lldb_private::ConstString PlatformKalimba::GetPluginName() {
  return GetPluginNameStatic(false);
}

void PlatformKalimba::Initialize() {
  Platform::Initialize();

  if (g_initialize_count++ == 0) {
    PluginManager::RegisterPlugin(
        PlatformKalimba::GetPluginNameStatic(false),
        PlatformKalimba::GetPluginDescriptionStatic(false),
        PlatformKalimba::CreateInstance);
  }
}

void PlatformKalimba::Terminate() {
  if (g_initialize_count > 0) {
    if (--g_initialize_count == 0) {
      PluginManager::UnregisterPlugin(PlatformKalimba::CreateInstance);
    }
  }

  Platform::Terminate();
}

//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformKalimba::PlatformKalimba(bool is_host)
    : Platform(is_host), // This is the local host platform
      m_remote_platform_sp() {}

//------------------------------------------------------------------
/// Destructor.
///
/// The destructor is virtual since this class is designed to be
/// inherited from by the plug-in instance.
//------------------------------------------------------------------
PlatformKalimba::~PlatformKalimba() {}

bool PlatformKalimba::GetSupportedArchitectureAtIndex(uint32_t idx,
                                                      ArchSpec &arch) {
  if (idx == 0) {
    arch = ArchSpec("kalimba3-csr-unknown");
    return true;
  }
  if (idx == 1) {
    arch = ArchSpec("kalimba4-csr-unknown");
    return true;
  }
  if (idx == 2) {
    arch = ArchSpec("kalimba5-csr-unknown");
    return true;
  }
  return false;
}

void PlatformKalimba::GetStatus(Stream &strm) { Platform::GetStatus(strm); }

size_t
PlatformKalimba::GetSoftwareBreakpointTrapOpcode(Target & /*target*/,
                                                 BreakpointSite * /*bp_site*/) {
  // the target hardware does not support software breakpoints
  return 0;
}

Status PlatformKalimba::LaunchProcess(ProcessLaunchInfo &launch_info) {
  Status error;

  if (IsHost()) {
    error.SetErrorString("native execution is not possible");
  } else {
    error.SetErrorString("the platform is not currently connected");
  }
  return error;
}

lldb::ProcessSP PlatformKalimba::Attach(ProcessAttachInfo &attach_info,
                                        Debugger &debugger, Target *target,
                                        Status &error) {
  lldb::ProcessSP process_sp;
  if (IsHost()) {
    error.SetErrorString("native execution is not possible");
  } else {
    if (m_remote_platform_sp)
      process_sp =
          m_remote_platform_sp->Attach(attach_info, debugger, target, error);
    else
      error.SetErrorString("the platform is not currently connected");
  }
  return process_sp;
}

void PlatformKalimba::CalculateTrapHandlerSymbolNames() {
  // TODO Research this sometime.
}