| 2403 | } |
| 2404 | |
| 2405 | CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type) |
| 2406 | { |
| 2407 | auto module = mCeMachine->mCeModule; |
| 2408 | auto ceContext = mCeMachine->mCurContext; |
| 2409 | |
| 2410 | if (constant->mConstType == BfConstType_GlobalVar) |
| 2411 | { |
| 2412 | auto globalVar = (BfGlobalVar*)constant; |
| 2413 | |
| 2414 | String varName(globalVar->mName); |
| 2415 | |
| 2416 | if (varName.StartsWith("__bfStrObj")) |
| 2417 | { |
| 2418 | int stringId = atoi(varName.c_str() + 10); |
| 2419 | auto addr = ceContext->GetString(stringId); |
| 2420 | return CeTypedValue(addr, globalVar->mType); |
| 2421 | } |
| 2422 | else if (varName.StartsWith("__bfStrData")) |
| 2423 | { |
| 2424 | auto stringType = module->ResolveTypeDef(module->mCompiler->mStringTypeDef)->ToTypeInstance(); |
| 2425 | int stringId = atoi(varName.c_str() + 11); |
| 2426 | auto addr = ceContext->GetString(stringId) + stringType->mInstSize; |
| 2427 | return CeTypedValue(addr, globalVar->mType); |
| 2428 | } |
| 2429 | |
| 2430 | CeStaticFieldInfo* fieldInfo = NULL; |
| 2431 | if (ceContext->mStaticFieldMap.TryAdd(globalVar->mName, NULL, &fieldInfo)) |
| 2432 | { |
| 2433 | auto dbgTypeInfo = GetDbgTypeInfo(globalVar->mType); |
| 2434 | if (dbgTypeInfo != NULL) |
| 2435 | { |
| 2436 | uint8* ptr = ceContext->CeMalloc(dbgTypeInfo->mType->mSize); |
| 2437 | if (dbgTypeInfo->mType->mSize > 0) |
| 2438 | memset(ptr, 0, dbgTypeInfo->mType->mSize); |
| 2439 | fieldInfo->mAddr = (addr_ce)(ptr - ceContext->mMemory.mVals); |
| 2440 | } |
| 2441 | else |
| 2442 | fieldInfo->mAddr = 0; |
| 2443 | } |
| 2444 | return CeTypedValue(fieldInfo->mAddr, globalVar->mType); |
| 2445 | } |
| 2446 | else if (constant->mTypeCode == BfTypeCode_StringId) |
| 2447 | { |
| 2448 | auto stringType = module->ResolveTypeDef(module->mCompiler->mStringTypeDef)->ToTypeInstance(); |
| 2449 | if ((type != NULL) && (type->IsPointer())) |
| 2450 | { |
| 2451 | BfType* charType = module->GetPrimitiveType(BfTypeCode_Char8); |
| 2452 | BfType* charPtrType = module->CreatePointerType(charType); |
| 2453 | auto addr = ceContext->GetString(constant->mInt32) + stringType->mInstSize; |
| 2454 | return CeTypedValue(addr, module->mBfIRBuilder->MapType(charPtrType)); |
| 2455 | } |
| 2456 | else |
| 2457 | { |
| 2458 | auto addr = ceContext->GetString(constant->mInt32); |
| 2459 | return CeTypedValue(addr, module->mBfIRBuilder->MapType(stringType)); |
| 2460 | } |
| 2461 | } |
| 2462 | else if (constant->mConstType == BfConstType_AggCE) |
no test coverage detected