[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Opcode.cpp --------------------------------------------------------===//
|
2011-03-25 07:53:38 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-03-25 07:53:38 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/Opcode.h"
|
|
|
|
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "lldb/Utility/DataBufferHeap.h"
|
|
|
|
#include "lldb/Utility/DataExtractor.h"
|
2017-02-15 03:06:07 +08:00
|
|
|
#include "lldb/Utility/Endian.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/lldb-forward.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <memory>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cinttypes>
|
2011-03-25 07:53:38 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
2011-03-26 02:03:16 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
int Opcode::Dump(Stream *s, uint32_t min_byte_width) {
|
2018-08-20 23:51:14 +08:00
|
|
|
const uint32_t previous_bytes = s->GetWrittenBytes();
|
2011-03-26 02:03:16 +08:00
|
|
|
switch (m_type) {
|
2013-10-04 23:29:20 +08:00
|
|
|
case Opcode::eTypeInvalid:
|
2018-08-20 23:51:14 +08:00
|
|
|
s->PutCString("<invalid>");
|
2011-03-26 02:03:16 +08:00
|
|
|
break;
|
2013-10-04 23:29:20 +08:00
|
|
|
case Opcode::eType8:
|
2018-08-20 23:51:14 +08:00
|
|
|
s->Printf("0x%2.2x", m_data.inst8);
|
2011-03-26 02:03:16 +08:00
|
|
|
break;
|
|
|
|
case Opcode::eType16:
|
2018-08-20 23:51:14 +08:00
|
|
|
s->Printf("0x%4.4x", m_data.inst16);
|
2011-03-26 02:03:16 +08:00
|
|
|
break;
|
2012-08-07 07:42:52 +08:00
|
|
|
case Opcode::eType16_2:
|
2011-03-26 02:03:16 +08:00
|
|
|
case Opcode::eType32:
|
2018-08-20 23:51:14 +08:00
|
|
|
s->Printf("0x%8.8x", m_data.inst32);
|
2011-03-26 02:03:16 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Opcode::eType64:
|
2018-08-20 23:51:14 +08:00
|
|
|
s->Printf("0x%16.16" PRIx64, m_data.inst64);
|
2011-03-26 02:03:16 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Opcode::eTypeBytes:
|
2016-03-12 05:55:47 +08:00
|
|
|
for (uint32_t i = 0; i < m_data.inst.length; ++i) {
|
|
|
|
if (i > 0)
|
2018-08-20 23:51:14 +08:00
|
|
|
s->PutChar(' ');
|
|
|
|
s->Printf("%2.2x", m_data.inst.bytes[i]);
|
2011-03-26 02:03:16 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-10-04 23:29:20 +08:00
|
|
|
|
2018-08-20 23:51:14 +08:00
|
|
|
uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes;
|
|
|
|
// Add spaces to make sure bytes display comes out even in case opcodes aren't
|
|
|
|
// all the same size.
|
|
|
|
if (bytes_written_so_far < min_byte_width)
|
|
|
|
s->Printf("%*s", min_byte_width - bytes_written_so_far, "");
|
|
|
|
return s->GetWrittenBytes() - previous_bytes;
|
2011-03-26 02:03:16 +08:00
|
|
|
}
|
|
|
|
|
2011-09-26 15:11:27 +08:00
|
|
|
lldb::ByteOrder Opcode::GetDataByteOrder() const {
|
2013-12-10 03:45:33 +08:00
|
|
|
if (m_byte_order != eByteOrderInvalid) {
|
|
|
|
return m_byte_order;
|
|
|
|
}
|
2011-09-26 15:11:27 +08:00
|
|
|
switch (m_type) {
|
|
|
|
case Opcode::eTypeInvalid:
|
|
|
|
break;
|
|
|
|
case Opcode::eType8:
|
|
|
|
case Opcode::eType16:
|
2012-08-07 07:42:52 +08:00
|
|
|
case Opcode::eType16_2:
|
2011-09-26 15:11:27 +08:00
|
|
|
case Opcode::eType32:
|
2015-11-07 12:40:13 +08:00
|
|
|
case Opcode::eType64:
|
|
|
|
return endian::InlHostByteOrder();
|
2011-09-26 15:11:27 +08:00
|
|
|
case Opcode::eTypeBytes:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return eByteOrderInvalid;
|
|
|
|
}
|
|
|
|
|
2012-08-07 09:44:58 +08:00
|
|
|
uint32_t Opcode::GetData(DataExtractor &data) const {
|
2012-04-12 05:13:31 +08:00
|
|
|
uint32_t byte_size = GetByteSize();
|
2013-12-10 03:45:33 +08:00
|
|
|
uint8_t swap_buf[8];
|
2016-03-12 05:55:47 +08:00
|
|
|
const void *buf = nullptr;
|
2013-10-04 23:29:20 +08:00
|
|
|
|
2012-04-12 05:13:31 +08:00
|
|
|
if (byte_size > 0) {
|
2013-12-10 03:45:33 +08:00
|
|
|
if (!GetEndianSwap()) {
|
|
|
|
if (m_type == Opcode::eType16_2) {
|
|
|
|
// 32 bit thumb instruction, we need to sizzle this a bit
|
|
|
|
swap_buf[0] = m_data.inst.bytes[2];
|
|
|
|
swap_buf[1] = m_data.inst.bytes[3];
|
|
|
|
swap_buf[2] = m_data.inst.bytes[0];
|
|
|
|
swap_buf[3] = m_data.inst.bytes[1];
|
|
|
|
buf = swap_buf;
|
|
|
|
} else {
|
|
|
|
buf = GetOpcodeDataBytes();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (m_type) {
|
|
|
|
case Opcode::eTypeInvalid:
|
|
|
|
break;
|
|
|
|
case Opcode::eType8:
|
|
|
|
buf = GetOpcodeDataBytes();
|
|
|
|
break;
|
|
|
|
case Opcode::eType16:
|
|
|
|
*(uint16_t *)swap_buf = llvm::ByteSwap_16(m_data.inst16);
|
|
|
|
buf = swap_buf;
|
|
|
|
break;
|
|
|
|
case Opcode::eType16_2:
|
|
|
|
swap_buf[0] = m_data.inst.bytes[1];
|
|
|
|
swap_buf[1] = m_data.inst.bytes[0];
|
|
|
|
swap_buf[2] = m_data.inst.bytes[3];
|
|
|
|
swap_buf[3] = m_data.inst.bytes[2];
|
|
|
|
buf = swap_buf;
|
|
|
|
break;
|
|
|
|
case Opcode::eType32:
|
|
|
|
*(uint32_t *)swap_buf = llvm::ByteSwap_32(m_data.inst32);
|
|
|
|
buf = swap_buf;
|
|
|
|
break;
|
|
|
|
case Opcode::eType64:
|
|
|
|
*(uint32_t *)swap_buf = llvm::ByteSwap_64(m_data.inst64);
|
|
|
|
buf = swap_buf;
|
|
|
|
break;
|
|
|
|
case Opcode::eTypeBytes:
|
|
|
|
buf = GetOpcodeDataBytes();
|
|
|
|
break;
|
2012-04-12 05:13:31 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-03-12 05:55:47 +08:00
|
|
|
if (buf != nullptr) {
|
2013-12-10 03:45:33 +08:00
|
|
|
DataBufferSP buffer_sp;
|
|
|
|
|
2017-04-07 05:28:29 +08:00
|
|
|
buffer_sp = std::make_shared<DataBufferHeap>(buf, byte_size);
|
2012-04-12 05:13:31 +08:00
|
|
|
data.SetByteOrder(GetDataByteOrder());
|
|
|
|
data.SetData(buffer_sp);
|
|
|
|
return byte_size;
|
|
|
|
}
|
|
|
|
data.Clear();
|
|
|
|
return 0;
|
|
|
|
}
|