本文整理汇总了C++中Thread类的典型用法代码示例。如果您正苦于以下问题:C++ Thread类的具体用法?C++ Thread怎么用?C++ Thread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Thread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setTitle
//.........这里部分代码省略.........
if(destFile.exists())
{
}
zipFile zf;
QByteArray dest = destPath.toLocal8Bit();
zf = zipOpen(dest.data(), APPEND_STATUS_CREATE);
if (zf == NULL)
{
QMessageBox::information(NULL, "提示", "打开压缩文件失败!");
return;
}
label_title->setText("压缩文件……");
// LOKI_ON_BLOCK_EXIT(zipClose, zf, (const char *)NULL);
for (int i=0; i<fileNames.size(); i++)
{
QString tempStr = fileNames.at(i);
QString path = releasePath;
path.remove("music");
QString temprel = path;
QString deststr = tempStr.remove(temprel);
if (!ZipAddFile(zf, deststr, fileNames.at(i), pwd, true)) //"default_yqc"
{
continue;
}
}
int errclose = zipClose(zf, NULL);
if (errclose != ZIP_OK)
qDebug() << " zipClose ret : " << errclose;
label_title->setText("上传压缩包……");
QFile file(destPath);
qDebug() << " size " << file.size();
if(file.size()/1024/1024 >= 1024)
{
QMessageBox::information(this, "提示", "上传文件大小必须小于1G!");
return;
}
///上传打包文件
// QString url;
// CurlUpload *curlUpload = new CurlUpload();
// bool ok = curlUpload->uploadYQDyun(destName, destPath, url);
// if(!ok)
// {
// url = "";
// label_title->setText("上传失败");
// label_title->setStyleSheet("color:rgb(255, 0, 0);");
// }
// else
// {
// label_title->setText("上传成功");
// label_title->setStyleSheet("color:rgb(0, 255, 0);");
// }
// qDebug() << " upload yun : ok : " << ok;
// qDebug() << " zip name " << destName;
// qDebug() << " url " << url;
// /// post 表格数据
QDateTime time = QDateTime::currentDateTime();
QString timeStr = time.toString("yyyy-MM-dd-hh-mm-ss");
int version = time.toTime_t(); ///时间戳
// QString postStr = QString("name=%1&url=%2&time=%3&remark=%4&version=%5")
// .arg(name)
// .arg(url)
// .arg(timeStr)
// .arg(pwd)
// .arg(version);
// CurlUpload *curlDownlaod = new CurlUpload();
// curlDownlaod->postJson(postStr);
_yun.name = name;
_yun.timeStr = timeStr;
_yun.pwd = pwd;
_yun.version = QString::number(version);
this->setCursor(Qt::ArrowCursor);
// return;
////
///线程上传
retSize = "-2";
Thread *workerThread = new Thread(this, 4);
connect(workerThread, &Thread::resultYun, this, &ReleaseDialog::uploadsuccess);
connect(workerThread, &Thread::start_upload, this, &ReleaseDialog::timeStart);
connect(workerThread, &Thread::finished, workerThread, &QObject::deleteLater);
workerThread->setUploadYun(destName, destPath, &retSize);
workerThread->start();
startValue = true;
}
示例2: target_sp
bool
ABIMacOSX_arm::PrepareTrivialCall (Thread &thread,
addr_t sp,
addr_t function_addr,
addr_t return_addr,
llvm::ArrayRef<addr_t> args) const
{
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return false;
const uint32_t pc_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
const uint32_t sp_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
const uint32_t ra_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);
RegisterValue reg_value;
const char *reg_names[] = { "r0", "r1", "r2", "r3" };
llvm::ArrayRef<addr_t>::iterator ai = args.begin(), ae = args.end();
for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i)
{
if (ai == ae)
break;
reg_value.SetUInt32(*ai);
if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName(reg_names[i]), reg_value))
return false;
++ai;
}
if (ai != ae)
{
// Spill onto the stack
size_t num_stack_regs = ae - ai;
sp -= (num_stack_regs * 4);
// Keep the stack 8 byte aligned, not that we need to
sp &= ~(8ull-1ull);
// just using arg1 to get the right size
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);
addr_t arg_pos = sp;
for (; ai != ae; ++ai)
{
reg_value.SetUInt32(*ai);
if (reg_ctx->WriteRegisterValueToMemory(reg_info, arg_pos, reg_info->byte_size, reg_value).Fail())
return false;
arg_pos += reg_info->byte_size;
}
}
TargetSP target_sp (thread.CalculateTarget());
Address so_addr;
// Figure out if our return address is ARM or Thumb by using the
// Address::GetCallableLoadAddress(Target*) which will figure out the ARM
// thumb-ness and set the correct address bits for us.
so_addr.SetLoadAddress (return_addr, target_sp.get());
return_addr = so_addr.GetCallableLoadAddress (target_sp.get());
// Set "lr" to the return address
if (!reg_ctx->WriteRegisterFromUnsigned (ra_reg_num, return_addr))
return false;
// Set "sp" to the requested value
if (!reg_ctx->WriteRegisterFromUnsigned (sp_reg_num, sp))
return false;
// If bit zero or 1 is set, this must be a thumb function, no need to figure
// this out from the symbols.
so_addr.SetLoadAddress (function_addr, target_sp.get());
function_addr = so_addr.GetCallableLoadAddress (target_sp.get());
const RegisterInfo *cpsr_reg_info = reg_ctx->GetRegisterInfoByName("cpsr");
const uint32_t curr_cpsr = reg_ctx->ReadRegisterAsUnsigned(cpsr_reg_info, 0);
// Make a new CPSR and mask out any Thumb IT (if/then) bits
uint32_t new_cpsr = curr_cpsr & ~MASK_CPSR_IT_MASK;
// If bit zero or 1 is set, this must be thumb...
if (function_addr & 1ull)
new_cpsr |= MASK_CPSR_T; // Set T bit in CPSR
else
new_cpsr &= ~MASK_CPSR_T; // Clear T bit in CPSR
if (new_cpsr != curr_cpsr)
{
if (!reg_ctx->WriteRegisterFromUnsigned (cpsr_reg_info, new_cpsr))
return false;
}
function_addr &= ~1ull; // clear bit zero since the CPSR will take care of the mode for us
// Set "pc" to the address requested
if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_num, function_addr))
return false;
//.........这里部分代码省略.........
示例3: if
ValueObjectSP
ABIMacOSX_arm::GetReturnValueObjectImpl (Thread &thread,
lldb_private::ClangASTType &clang_type) const
{
Value value;
ValueObjectSP return_valobj_sp;
if (!clang_type)
return return_valobj_sp;
clang::ASTContext *ast_context = clang_type.GetASTContext();
if (!ast_context)
return return_valobj_sp;
//value.SetContext (Value::eContextTypeClangType, clang_type.GetOpaqueQualType());
value.SetClangType (clang_type);
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return return_valobj_sp;
bool is_signed;
// Get the pointer to the first stack argument so we have a place to start
// when reading data
const RegisterInfo *r0_reg_info = reg_ctx->GetRegisterInfoByName("r0", 0);
if (clang_type.IsIntegerType (is_signed))
{
size_t bit_width = clang_type.GetBitSize();
switch (bit_width)
{
default:
return return_valobj_sp;
case 64:
{
const RegisterInfo *r1_reg_info = reg_ctx->GetRegisterInfoByName("r1", 0);
uint64_t raw_value;
raw_value = reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX;
raw_value |= ((uint64_t)(reg_ctx->ReadRegisterAsUnsigned(r1_reg_info, 0) & UINT32_MAX)) << 32;
if (is_signed)
value.GetScalar() = (int64_t)raw_value;
else
value.GetScalar() = (uint64_t)raw_value;
}
break;
case 32:
if (is_signed)
value.GetScalar() = (int32_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX);
else
value.GetScalar() = (uint32_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX);
break;
case 16:
if (is_signed)
value.GetScalar() = (int16_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT16_MAX);
else
value.GetScalar() = (uint16_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT16_MAX);
break;
case 8:
if (is_signed)
value.GetScalar() = (int8_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT8_MAX);
else
value.GetScalar() = (uint8_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT8_MAX);
break;
}
}
else if (clang_type.IsPointerType ())
{
uint32_t ptr = thread.GetRegisterContext()->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX;
value.GetScalar() = ptr;
}
else
{
// not handled yet
return return_valobj_sp;
}
// If we get here, we have a valid Value, so make our ValueObject out of it:
return_valobj_sp = ValueObjectConstResult::Create(thread.GetStackFrameAtIndex(0).get(),
value,
ConstString(""));
return return_valobj_sp;
}
示例4: IndexMatches
bool ThreadSpec::IndexMatches(Thread &thread) const {
if (m_index == UINT32_MAX)
return true;
uint32_t index = thread.GetIndexID();
return IndexMatches(index);
}
示例5: assert
void Thread::split(Position& pos, SearchStack* ss, const Score alpha, const Score beta, Score& bestScore,
Move& bestMove, const Depth depth, const Move threatMove, const int moveCount,
MovePicker& mp, const NodeType nodeType, const bool cutNode)
{
assert(pos.isOK());
assert(bestScore <= alpha && alpha < beta && beta <= ScoreInfinite);
assert(-ScoreInfinite < bestScore);
assert(searcher->threads.minSplitDepth() <= depth);
assert(searching);
assert(splitPointsSize < MaxSplitPointsPerThread);
SplitPoint& sp = splitPoints[splitPointsSize];
sp.masterThread = this;
sp.parentSplitPoint = activeSplitPoint;
sp.slavesMask = UINT64_C(1) << idx;
sp.depth = depth;
sp.bestMove = bestMove;
sp.threatMove = threatMove;
sp.alpha = alpha;
sp.beta = beta;
sp.nodeType = nodeType;
sp.cutNode = cutNode;
sp.bestScore = bestScore;
sp.movePicker = ∓
sp.moveCount = moveCount;
sp.pos = &pos;
sp.nodes = 0;
sp.cutoff = false;
sp.ss = ss;
searcher->threads.mutex_.lock();
sp.mutex.lock();
++splitPointsSize;
activeSplitPoint = &sp;
activePosition = nullptr;
// thisThread が常に含まれるので 1
size_t slavesCount = 1;
Thread* slave;
while ((slave = searcher->threads.availableSlave(this)) != nullptr
&& ++slavesCount <= searcher->threads.maxThreadsPerSplitPoint_ && !Fake)
{
sp.slavesMask |= UINT64_C(1) << slave->idx;
slave->activeSplitPoint = &sp;
slave->searching = true;
slave->notifyOne();
}
if (1 < slavesCount || Fake) {
sp.mutex.unlock();
searcher->threads.mutex_.unlock();
Thread::idleLoop();
assert(!searching);
assert(!activePosition);
searcher->threads.mutex_.lock();
sp.mutex.lock();
}
searching = true;
--splitPointsSize;
activeSplitPoint = sp.parentSplitPoint;
activePosition = &pos;
pos.setNodesSearched(pos.nodesSearched() + sp.nodes);
bestMove = sp.bestMove;
bestScore = sp.bestScore;
searcher->threads.mutex_.unlock();
sp.mutex.unlock();
}
示例6: test_memover1
void test_memover1(void)
{
VM::setAlertGCCallback(alertGC);
Bytecode* myBytecode = gCodeManager.readBytecode("test.hyb");
CPPUNIT_ASSERT(myBytecode != NULL);
myBytecode->setInitialized();
Value mcls(HC_Class, (void*) myBytecode->mainClass());
alert_count = prev_alert_count = 0;
int c = 0;
while (c < 30) {
Context* context = gCodeManager.createContext();
Thread* pThread = gThreadManager.createTmpThread();
pThread->initialize(context);
context->pushInt(10);
context->methodCall(mcls, HSym_create_XClass, 1);
pThread->start();
while (pThread->isActive())
pThread->exec1tick();
context->pop();
gCodeManager.releaseContext(context);
if (check_alert()) ++c;
}
c = 0;
while (c < 30) {
Context* context = gCodeManager.createContext();
Thread* pThread = gThreadManager.createTmpThread();
pThread->initialize(context);
context->pushInt(500);
context->methodCall(mcls, HSym_create_XClass, 1);
pThread->start();
while (pThread->isActive())
pThread->exec1tick();
context->pop();
gCodeManager.releaseContext(context);
if (check_alert()) ++c;
}
c = 0;
while (c < 30) {
Context* context = gCodeManager.createContext();
Thread* pThread = gThreadManager.createTmpThread();
pThread->initialize(context);
context->methodCall(mcls, HSym_create_YClass, 0);
pThread->start();
while (pThread->isActive())
pThread->exec1tick();
context->pop();
gCodeManager.releaseContext(context);
if (check_alert()) ++c;
}
}
示例7: if
ValueObjectSP
ABISysV_arm::GetReturnValueObjectImpl (Thread &thread,
lldb_private::CompilerType &compiler_type) const
{
Value value;
ValueObjectSP return_valobj_sp;
if (!compiler_type)
return return_valobj_sp;
//value.SetContext (Value::eContextTypeClangType, compiler_type.GetOpaqueQualType());
value.SetCompilerType (compiler_type);
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return return_valobj_sp;
bool is_signed;
bool is_complex;
uint32_t float_count;
// Get the pointer to the first stack argument so we have a place to start
// when reading data
const RegisterInfo *r0_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);
size_t bit_width = compiler_type.GetBitSize(&thread);
if (compiler_type.IsIntegerType (is_signed))
{
switch (bit_width)
{
default:
return return_valobj_sp;
case 64:
{
const RegisterInfo *r1_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2);
uint64_t raw_value;
raw_value = reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX;
raw_value |= ((uint64_t)(reg_ctx->ReadRegisterAsUnsigned(r1_reg_info, 0) & UINT32_MAX)) << 32;
if (is_signed)
value.GetScalar() = (int64_t)raw_value;
else
value.GetScalar() = (uint64_t)raw_value;
}
break;
case 32:
if (is_signed)
value.GetScalar() = (int32_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX);
else
value.GetScalar() = (uint32_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX);
break;
case 16:
if (is_signed)
value.GetScalar() = (int16_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT16_MAX);
else
value.GetScalar() = (uint16_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT16_MAX);
break;
case 8:
if (is_signed)
value.GetScalar() = (int8_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT8_MAX);
else
value.GetScalar() = (uint8_t)(reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT8_MAX);
break;
}
}
else if (compiler_type.IsPointerType ())
{
uint32_t ptr = thread.GetRegisterContext()->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX;
value.GetScalar() = ptr;
}
else if (compiler_type.IsVectorType(nullptr, nullptr))
{
size_t byte_size = compiler_type.GetByteSize(&thread);
if (byte_size <= 16)
{
DataBufferHeap buffer(16, 0);
uint32_t* buffer_ptr = (uint32_t*)buffer.GetBytes();
for (uint32_t i = 0; 4*i < byte_size; ++i)
{
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
buffer_ptr[i] = reg_ctx->ReadRegisterAsUnsigned(reg_info, 0) & UINT32_MAX;
}
value.SetBytes(buffer.GetBytes(), byte_size);
}
else
{
if (!GetReturnValuePassedInMemory(thread, reg_ctx, byte_size, value))
return return_valobj_sp;
}
}
else if (compiler_type.IsFloatingPointType(float_count, is_complex))
{
if (float_count == 1 && !is_complex)
{
switch (bit_width)
{
default:
return return_valobj_sp;
case 64:
//.........这里部分代码省略.........
示例8: sizeof
ValueObjectSP
ABISysV_ppc::GetReturnValueObjectSimple (Thread &thread,
ClangASTType &return_clang_type) const
{
ValueObjectSP return_valobj_sp;
Value value;
if (!return_clang_type)
return return_valobj_sp;
//value.SetContext (Value::eContextTypeClangType, return_value_type);
value.SetClangType (return_clang_type);
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return return_valobj_sp;
const uint32_t type_flags = return_clang_type.GetTypeInfo ();
if (type_flags & eTypeIsScalar)
{
value.SetValueType(Value::eValueTypeScalar);
bool success = false;
if (type_flags & eTypeIsInteger)
{
// Extract the register context so we can read arguments from registers
const size_t byte_size = return_clang_type.GetByteSize(nullptr);
uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(reg_ctx->GetRegisterInfoByName("r3", 0), 0);
const bool is_signed = (type_flags & eTypeIsSigned) != 0;
switch (byte_size)
{
default:
break;
case sizeof(uint64_t):
if (is_signed)
value.GetScalar() = (int64_t)(raw_value);
else
value.GetScalar() = (uint64_t)(raw_value);
success = true;
break;
case sizeof(uint32_t):
if (is_signed)
value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
else
value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
success = true;
break;
case sizeof(uint16_t):
if (is_signed)
value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
else
value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
success = true;
break;
case sizeof(uint8_t):
if (is_signed)
value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
else
value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
success = true;
break;
}
}
else if (type_flags & eTypeIsFloat)
{
if (type_flags & eTypeIsComplex)
{
// Don't handle complex yet.
}
else
{
const size_t byte_size = return_clang_type.GetByteSize(nullptr);
if (byte_size <= sizeof(long double))
{
const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
RegisterValue f1_value;
if (reg_ctx->ReadRegister (f1_info, f1_value))
{
DataExtractor data;
if (f1_value.GetData(data))
{
lldb::offset_t offset = 0;
if (byte_size == sizeof(float))
{
value.GetScalar() = (float) data.GetFloat(&offset);
success = true;
}
else if (byte_size == sizeof(double))
{
value.GetScalar() = (double) data.GetDouble(&offset);
success = true;
}
}
}
}
//.........这里部分代码省略.........
示例9: exe_ctx
ValueObjectSP
ABISysV_ppc::GetReturnValueObjectImpl (Thread &thread, ClangASTType &return_clang_type) const
{
ValueObjectSP return_valobj_sp;
if (!return_clang_type)
return return_valobj_sp;
ExecutionContext exe_ctx (thread.shared_from_this());
return_valobj_sp = GetReturnValueObjectSimple(thread, return_clang_type);
if (return_valobj_sp)
return return_valobj_sp;
RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
if (!reg_ctx_sp)
return return_valobj_sp;
const size_t bit_width = return_clang_type.GetBitSize(&thread);
if (return_clang_type.IsAggregateType())
{
Target *target = exe_ctx.GetTargetPtr();
bool is_memory = true;
if (bit_width <= 128)
{
ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
DataBufferSP data_sp (new DataBufferHeap(16, 0));
DataExtractor return_ext (data_sp,
target_byte_order,
target->GetArchitecture().GetAddressByteSize());
const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
const RegisterInfo *rdx_info = reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
RegisterValue r3_value, rdx_value;
reg_ctx_sp->ReadRegister (r3_info, r3_value);
reg_ctx_sp->ReadRegister (rdx_info, rdx_value);
DataExtractor r3_data, rdx_data;
r3_value.GetData(r3_data);
rdx_value.GetData(rdx_data);
uint32_t fp_bytes = 0; // Tracks how much of the xmm registers we've consumed so far
uint32_t integer_bytes = 0; // Tracks how much of the r3/rds registers we've consumed so far
const uint32_t num_children = return_clang_type.GetNumFields ();
// Since we are in the small struct regime, assume we are not in memory.
is_memory = false;
for (uint32_t idx = 0; idx < num_children; idx++)
{
std::string name;
uint64_t field_bit_offset = 0;
bool is_signed;
bool is_complex;
uint32_t count;
ClangASTType field_clang_type = return_clang_type.GetFieldAtIndex (idx, name, &field_bit_offset, NULL, NULL);
const size_t field_bit_width = field_clang_type.GetBitSize(&thread);
// If there are any unaligned fields, this is stored in memory.
if (field_bit_offset % field_bit_width != 0)
{
is_memory = true;
break;
}
uint32_t field_byte_width = field_bit_width/8;
uint32_t field_byte_offset = field_bit_offset/8;
DataExtractor *copy_from_extractor = NULL;
uint32_t copy_from_offset = 0;
if (field_clang_type.IsIntegerType (is_signed) || field_clang_type.IsPointerType ())
{
if (integer_bytes < 8)
{
if (integer_bytes + field_byte_width <= 8)
{
// This is in RAX, copy from register to our result structure:
copy_from_extractor = &r3_data;
copy_from_offset = integer_bytes;
integer_bytes += field_byte_width;
}
else
{
// The next field wouldn't fit in the remaining space, so we pushed it to rdx.
copy_from_extractor = &rdx_data;
copy_from_offset = 0;
integer_bytes = 8 + field_byte_width;
}
}
else if (integer_bytes + field_byte_width <= 16)
{
copy_from_extractor = &rdx_data;
copy_from_offset = integer_bytes - 8;
integer_bytes += field_byte_width;
//.........这里部分代码省略.........
示例10: if
bool
ABISysV_ppc::GetArgumentValues (Thread &thread,
ValueList &values) const
{
unsigned int num_values = values.GetSize();
unsigned int value_index;
// Extract the register context so we can read arguments from registers
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return false;
// Get the pointer to the first stack argument so we have a place to start
// when reading data
addr_t sp = reg_ctx->GetSP(0);
if (!sp)
return false;
addr_t current_stack_argument = sp + 48; // jump over return address
uint32_t argument_register_ids[8];
argument_register_ids[0] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)->kinds[eRegisterKindLLDB];
argument_register_ids[1] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)->kinds[eRegisterKindLLDB];
argument_register_ids[2] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)->kinds[eRegisterKindLLDB];
argument_register_ids[3] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)->kinds[eRegisterKindLLDB];
argument_register_ids[4] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)->kinds[eRegisterKindLLDB];
argument_register_ids[5] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG6)->kinds[eRegisterKindLLDB];
argument_register_ids[6] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG7)->kinds[eRegisterKindLLDB];
argument_register_ids[7] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG8)->kinds[eRegisterKindLLDB];
unsigned int current_argument_register = 0;
for (value_index = 0;
value_index < num_values;
++value_index)
{
Value *value = values.GetValueAtIndex(value_index);
if (!value)
return false;
// We currently only support extracting values with Clang QualTypes.
// Do we care about others?
ClangASTType clang_type = value->GetClangType();
if (!clang_type)
return false;
bool is_signed;
if (clang_type.IsIntegerType (is_signed))
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(&thread),
is_signed,
thread,
argument_register_ids,
current_argument_register,
current_stack_argument);
}
else if (clang_type.IsPointerType ())
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(&thread),
false,
thread,
argument_register_ids,
current_argument_register,
current_stack_argument);
}
}
return true;
}
示例11: process_sp
bool
ABISysV_ppc::PrepareTrivialCall (Thread &thread,
addr_t sp,
addr_t func_addr,
addr_t return_addr,
llvm::ArrayRef<addr_t> args) const
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
if (log)
{
StreamString s;
s.Printf("ABISysV_ppc::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64,
thread.GetID(),
(uint64_t)sp,
(uint64_t)func_addr,
(uint64_t)return_addr);
for (size_t i = 0; i < args.size(); ++i)
s.Printf (", arg%zd = 0x%" PRIx64, i + 1, args[i]);
s.PutCString (")");
log->PutCString(s.GetString().c_str());
}
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return false;
const RegisterInfo *reg_info = NULL;
if (args.size() > 8) // TODO handle more than 8 arguments
return false;
for (size_t i = 0; i < args.size(); ++i)
{
reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
if (log)
log->Printf("About to write arg%zd (0x%" PRIx64 ") into %s", i + 1, args[i], reg_info->name);
if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
return false;
}
// First, align the SP
if (log)
log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64, (uint64_t)sp, (uint64_t)(sp & ~0xfull));
sp &= ~(0xfull); // 16-byte alignment
sp -= 8;
Error error;
const RegisterInfo *pc_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
ProcessSP process_sp (thread.GetProcess());
RegisterValue reg_value;
#if 0
// This code adds an extra frame so that we don't lose the function that we came from
// by pushing the PC and the FP and then writing the current FP to point to the FP value
// we just pushed. It is disabled for now until the stack backtracing code can be debugged.
// Save current PC
const RegisterInfo *fp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP);
if (reg_ctx->ReadRegister(pc_reg_info, reg_value))
{
if (log)
log->Printf("Pushing the current PC onto the stack: 0x%" PRIx64 ": 0x%" PRIx64, (uint64_t)sp, reg_value.GetAsUInt64());
if (!process_sp->WritePointerToMemory(sp, reg_value.GetAsUInt64(), error))
return false;
sp -= 8;
// Save current FP
if (reg_ctx->ReadRegister(fp_reg_info, reg_value))
{
if (log)
log->Printf("Pushing the current FP onto the stack: 0x%" PRIx64 ": 0x%" PRIx64, (uint64_t)sp, reg_value.GetAsUInt64());
if (!process_sp->WritePointerToMemory(sp, reg_value.GetAsUInt64(), error))
return false;
}
// Setup FP backchain
reg_value.SetUInt64 (sp);
if (log)
log->Printf("Writing FP: 0x%" PRIx64 " (for FP backchain)", reg_value.GetAsUInt64());
if (!reg_ctx->WriteRegister(fp_reg_info, reg_value))
{
return false;
}
sp -= 8;
}
#endif
if (log)
//.........这里部分代码省略.........
示例12: ExecInAnyThread
/// <summary>
/// Execute code in context of any existing thread
/// </summary>
/// <param name="pCode">Cde to execute</param>
/// <param name="size">Code size.</param>
/// <param name="callResult">Execution result</param>
/// <param name="thd">Target thread</param>
/// <returns>Status</returns>
NTSTATUS RemoteExec::ExecInAnyThread( PVOID pCode, size_t size, uint64_t& callResult, Thread& thd )
{
NTSTATUS dwResult = STATUS_SUCCESS;
CONTEXT_T ctx;
// Prepare for remote exec
CreateRPCEnvironment( true );
// Write code
dwResult = CopyCode( pCode, size );
if (dwResult != STATUS_SUCCESS)
return dwResult;
if (_hWaitEvent)
ResetEvent( _hWaitEvent );
if (!thd.Suspend())
return LastNtStatus();
if (thd.GetContext( ctx, CONTEXT_ALL, true ))
{
AsmJit::Assembler a;
AsmJitHelper ah( a );
#ifdef _M_AMD64
const int count = 15;
AsmJit::GPReg regs[] = { AsmJit::rax, AsmJit::rbx, AsmJit::rcx, AsmJit::rdx, AsmJit::rsi,
AsmJit::rdi, AsmJit::r8, AsmJit::r9, AsmJit::r10, AsmJit::r11,
AsmJit::r12, AsmJit::r13, AsmJit::r14, AsmJit::r15, AsmJit::rbp
};
//
// Preserve thread context
// I don't care about FPU, XMM and anything else
//
a.sub(AsmJit::rsp, count * WordSize); // Stack must be aligned on 16 bytes
a.pushfq(); //
// Save registers
for (int i = 0; i < count; i++)
a.mov( AsmJit::Mem( AsmJit::rsp, i * WordSize ), regs[i] );
ah.GenCall( _userCode.ptr<size_t>(), { _userData.ptr<size_t>() } );
AddReturnWithEvent( ah, rt_int32, INTRET_OFFSET );
// Restore registers
for (int i = 0; i < count; i++)
a.mov( regs[i], AsmJit::Mem( AsmJit::rsp, i * WordSize ) );
a.popfq();
a.add( AsmJit::rsp, count * WordSize );
a.jmp( ctx.Rip );
#else
a.pushad();
a.pushfd();
ah.GenCall( _userCode.ptr<size_t>(), { _userData.ptr<size_t>() } );
AddReturnWithEvent( ah, rt_int32, INTRET_OFFSET );
a.popfd();
a.popad();
a.push( ctx.NIP );
a.ret();
#endif
if (_userCode.Write( size, a.getCodeSize(), a.make() ) == STATUS_SUCCESS)
{
ctx.NIP = _userCode.ptr<size_t>() + size;
if (!thd.SetContext( ctx, true ))
dwResult = LastNtStatus();
}
else
dwResult = LastNtStatus();
}
else
dwResult = LastNtStatus();
thd.Resume();
if (dwResult == STATUS_SUCCESS)
{
WaitForSingleObject( _hWaitEvent, INFINITE );
callResult = _userData.Read<size_t>( INTRET_OFFSET, 0 );
}
return dwResult;
}
示例13: SetIsMasterPlan
//----------------------------------------------------------------------
// ThreadPlanCallFunction: Plan to call a single function
//----------------------------------------------------------------------
bool
ThreadPlanCallFunction::ConstructorSetup (Thread &thread,
ABI *& abi,
lldb::addr_t &start_load_addr,
lldb::addr_t &function_load_addr)
{
SetIsMasterPlan (true);
SetOkayToDiscard (false);
SetPrivate (true);
ProcessSP process_sp (thread.GetProcess());
if (!process_sp)
return false;
abi = process_sp->GetABI().get();
if (!abi)
return false;
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP));
SetBreakpoints();
m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
// If we can't read memory at the point of the process where we are planning to put our function, we're
// not going to get any further...
Error error;
process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
if (!error.Success())
{
m_constructor_errors.Printf ("Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", m_function_sp);
if (log)
log->Printf ("ThreadPlanCallFunction(%p): %s.",
static_cast<void*>(this),
m_constructor_errors.GetData());
return false;
}
Module *exe_module = GetTarget().GetExecutableModulePointer();
if (exe_module == NULL)
{
m_constructor_errors.Printf ("Can't execute code without an executable module.");
if (log)
log->Printf ("ThreadPlanCallFunction(%p): %s.",
static_cast<void*>(this),
m_constructor_errors.GetData());
return false;
}
else
{
ObjectFile *objectFile = exe_module->GetObjectFile();
if (!objectFile)
{
m_constructor_errors.Printf ("Could not find object file for module \"%s\".",
exe_module->GetFileSpec().GetFilename().AsCString());
if (log)
log->Printf ("ThreadPlanCallFunction(%p): %s.",
static_cast<void*>(this),
m_constructor_errors.GetData());
return false;
}
m_start_addr = objectFile->GetEntryPointAddress();
if (!m_start_addr.IsValid())
{
m_constructor_errors.Printf ("Could not find entry point address for executable module \"%s\".",
exe_module->GetFileSpec().GetFilename().AsCString());
if (log)
log->Printf ("ThreadPlanCallFunction(%p): %s.",
static_cast<void*>(this),
m_constructor_errors.GetData());
return false;
}
}
start_load_addr = m_start_addr.GetLoadAddress (&GetTarget());
// Checkpoint the thread state so we can restore it later.
if (log && log->GetVerbose())
ReportRegisterState ("About to checkpoint thread before function call. Original register state was:");
if (!thread.CheckpointThreadState (m_stored_thread_state))
{
m_constructor_errors.Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state.");
if (log)
log->Printf ("ThreadPlanCallFunction(%p): %s.",
static_cast<void*>(this),
m_constructor_errors.GetData());
return false;
}
function_load_addr = m_function_addr.GetLoadAddress (&GetTarget());
return true;
}
示例14: test_instance
void test_instance(void)
{
MemPool* pool = gMemPool;
// ffi定義が無いのでbindFfiClassTable不要
Bytecode* myBytecode = gCodeManager.readBytecode("test.hyb");
CPPUNIT_ASSERT(myBytecode != NULL);
myBytecode->setInitialized();
// gc_test_instance() をスレッドで実行
Thread* pThread = gThreadManager.createTmpThread();
Context* context = gCodeManager.createContext();
pThread->initialize(context);
context->pushClass(myBytecode->mainClass());
context->methodCall(HSym_gc_test_instance, 0);
gCodeManager.releaseContext(context); // contextのdeleteはGCまかせ
pThread->start();
GC::full();
pThread->exec1tick();
int n, m;
n = GC::countObjects(pool); // start
pThread->exec1tick();
GC::full();
m = GC::countObjects(pool);
CPPUNIT_ASSERT_EQUAL(n-1, m); // -1
pThread->exec1tick();
GC::full();
n = GC::countObjects(pool);
CPPUNIT_ASSERT_EQUAL(m, n); // -0
pThread->exec1tick();
GC::full();
m = GC::countObjects(pool);
CPPUNIT_ASSERT_EQUAL(n, m); // -0
pThread->exec1tick();
GC::full();
n = GC::countObjects(pool);
CPPUNIT_ASSERT_EQUAL(m-3, n); // -3
pThread->exec1tick();
GC::full();
m = GC::countObjects(pool);
CPPUNIT_ASSERT_EQUAL(n-1, m); // -1
CPPUNIT_ASSERT_EQUAL(Thread::WAITING_TICK, pThread->state());
pThread->exec1tick();
CPPUNIT_ASSERT_EQUAL(Thread::TERMINATED, pThread->state());
GC::full();
n = GC::countObjects(pool);
CPPUNIT_ASSERT_EQUAL(m-2, n); // -2
// pThread,context は GC に回収されている
}
示例15: trampoline
static void* trampoline(void* arg) {
Thread* self = reinterpret_cast<Thread*>(arg);
self->perform();
if(self->delete_on_exit()) delete self;
return NULL;
}