Skip to content

Commit

Permalink
[mono][debugger] Implementing mscordbi to support iCorDebug on mono r…
Browse files Browse the repository at this point in the history
…untime (#47639)

* Implementing mscordbi on mono to support icordebug

* Fix eval, fix step and cancel step, remove suspend status on mscordbi

* Using log from coreclr as mscordbi does

* Missing files

* Removing eglib from implementation

* Compiling on Mac

* Compiling and Working on windows.
Changing what @lambdageek suggested about mono_atomic_inc_i32

* Generating libmscordbi on mac

* Fix socket on mac

* Counting references, deleting objects, removing unecessary properties,
formating with cland-format, renaming properties to follow the used
pattern.

* Checking error when get reply from debugger

* Fix format, reuse regmeta from coreclr and try to fix compilation on
windows

* Dont build when target is android or ios or wasm

* Fix error unused variable

* Fixing error: 'CFUserNotificationDisplayAlert' is unavailable: not
available on macCatalyst

* Fix compilation error on Linux

* Fix function not found in maccatalyst
Fix warning as error of macro redefinition

* Dont compile mscordbi on maccatalyst

* Fix compilation on linux

* Fix compilation on android, ios and browser

* Fix compilation on linux

* Fix cross compiling

* Fix compilation x86 windows

* Fix x86 compilation

* Fix compilation on windows

* Fix cmake error

* Fix cmake

* Fix arm64 mac

* Fix windows compilation

* Fix memory leak

* Returning E_NOTIMPL where it was possible and it's not implemented as
suggested by @cshung

* Fix what @cshung

* Use only one ref count

* Adding ex_try everywhere that we could have an allocation failure.

* Implementing get class

* Apply suggestions from code review

Co-authored-by: Noah Falk <noahfalk@users.noreply.github.com>

* Fix what @noahfalk suggested in his review.

* Fixing what was suggested by @viniciusjarina

* Fix what was suggested by @viniciusjarina

* Changing what @noahfalk suggested

* Accept more than 1 stepper per thread

* Changing what was suggested by @noahfalk

* Using CORDB_ADDRESS to return addresses from debugged process

* Fix eval

* Update src/mono/mono/mini/debugger-agent.c

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>

* Using 1:1 with runtime for cordbtype and cordbclass

* Rnaming methods as suggested by @lambdageek

* Update src/mono/dbi/cordb-process.h

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>

* Update CMakeLists.txt

* Fix arm64 compilation

* Fix arm64 compilation

* Fix error cmake

* fix arm64 compilation

* Fix arm64 compilation

* Fix arm64 compilation

* Fix arm64 compilation

* Revert "Fix arm64 compilation"

This reverts commit 25f24bc.

* Revert "Fix arm64 compilation"

This reverts commit a8f0318.

* Revert "fix arm64 compilation"

This reverts commit b5de06d.

* Revert "Fix error cmake"

This reverts commit 2aae463.

* Revert "Fix arm64 compilation"

This reverts commit ae5f701.

* Revert "Fix arm64 compilation"

This reverts commit 94d957c.

* Removing arm64 compilation

* Remove arm64 compilation

Co-authored-by: Noah Falk <noahfalk@users.noreply.github.com>
Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
  • Loading branch information
3 people authored Mar 12, 2021
1 parent 686f752 commit fe8bc17
Show file tree
Hide file tree
Showing 62 changed files with 8,411 additions and 60 deletions.
4 changes: 2 additions & 2 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux)
set(CLR_CMAKE_HOST_UNIX_ARMV7L 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a)
set(CLR_CMAKE_HOST_UNIX_ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686 OR CMAKE_SYSTEM_PROCESSOR STREQUAL x86)
set(CLR_CMAKE_HOST_UNIX_X86 1)
else()
clr_unknown_arch()
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/clrdefinitions.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(clrfeatures.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/clrfeatures.cmake)

add_compile_definitions($<$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>:DACCESS_COMPILE>)
add_compile_definitions($<$<BOOL:$<TARGET_PROPERTY:CROSSGEN_COMPONENT>>:CROSSGEN_COMPILE>)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1402,4 +1402,4 @@ check_prototype_definition(
${STATFS_INCLUDES}
HAVE_NON_LEGACY_STATFS)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/libunwind/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main(void)
return result;
}" HAVE_STDALIGN_ALIGNAS)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
add_definitions(-DHAVE_CONFIG_H=1)

configure_file(include/libunwind-common.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/libunwind-common.h)
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/pal/src/synchmgr/synchmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4623,7 +4623,11 @@ namespace CorUnix
ptsAbsTmo->tv_nsec = tv.tv_usec * tccMicroSecondsToNanoSeconds;
}
#else
#error "Don't know how to get hi-res current time on this platform"
#ifdef DBI_COMPONENT_MONO
return ERROR_INTERNAL_ERROR;
#else
#error "Don't know how to get hi-res current time on this platform"
#endif
#endif // HAVE_WORKING_CLOCK_GETTIME, HAVE_WORKING_GETTIMEOFDAY
#if HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK
}
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/utilcode/ccomprc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ HRESULT CCompRC::LoadString(ResourceCategory eCategory, UINT iResourceID, __out_

HRESULT CCompRC::LoadString(ResourceCategory eCategory, LocaleID langId, UINT iResourceID, __out_ecount(iMax) LPWSTR szBuffer, int iMax, int *pcwchUsed)
{
#ifdef DBI_COMPONENT_MONO
return E_NOTIMPL;
#else
CONTRACTL
{
GC_NOTRIGGER;
Expand Down Expand Up @@ -535,6 +538,7 @@ HRESULT CCompRC::LoadString(ResourceCategory eCategory, LocaleID langId, UINT iR
return LoadNativeStringResource(NATIVE_STRING_RESOURCE_TABLE(NATIVE_STRING_RESOURCE_NAME), iResourceID,
szBuffer, iMax, pcwchUsed);
#endif // HOST_WINDOWS
#endif
}

#ifndef DACCESS_COMPILE
Expand Down
8 changes: 8 additions & 0 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ endif()

project(mono)

set(CMAKE_C_FLAGS_CHECKED "")
set(CMAKE_CXX_FLAGS_CHECKED "")
set(CMAKE_EXE_LINKER_FLAGS_CHECKED "")
set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "")

include(GNUInstallDirs)
include(CheckIncludeFile)
include(CheckFunctionExists)
Expand Down Expand Up @@ -702,6 +707,9 @@ endif()
### End of OS specific checks

add_subdirectory(mono)
if (NOT TARGET_ARCH STREQUAL "arm64" AND NOT CMAKE_CROSSCOMPILING AND NOT TARGET_IOS AND NOT TARGET_ANDROID AND NOT TARGET_BROWSER AND NOT HOST_MACCATALYST)
add_subdirectory(dbi)
endif()

configure_file(cmake/config.h.in config.h)
configure_file(cmake/eglib-config.h.cmake.in mono/eglib/eglib-config.h) # TODO: eglib-config.h is not needed, we're using hardcoded eglib-config.hw
151 changes: 151 additions & 0 deletions src/mono/dbi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
project(mscordbi)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CLR_DIR ${PROJECT_SOURCE_DIR}/../../coreclr)
set(VM_DIR ${PROJECT_SOURCE_DIR}/../../coreclr/vm)
set(CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR})
set(CMAKE_EXE_LINKER_FLAGS_CHECKED "")
set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "")
set(CLR_CMAKE_HOST_ARCH ${CMAKE_GENERATOR_PLATFORM})
set(FEATURE_EVENT_TRACE 0)

if(HOST_WIN32)
if(HOST_X86)
set(CLR_CMAKE_HOST_ARCH x86)
elseif(HOST_ARM64)
set(CLR_CMAKE_HOST_ARCH arm64)
elseif(HOST_ARM)
set(CLR_CMAKE_HOST_ARCH arm)
elseif(HOST_AMD64)
set(CLR_CMAKE_HOST_ARCH x64)
endif()
endif()

add_definitions(-DDBI_COMPONENT_MONO)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../..
${PROJECT_SOURCE_DIR}/../
${PROJECT_SOURCE_DIR}/../dbi
${PROJECT_SOURCE_DIR}/../dbi/socket-dbi
${PROJECT_SOURCE_DIR}/../../coreclr/md/enc
${PROJECT_SOURCE_DIR}/../../coreclr/inc
${PROJECT_SOURCE_DIR}/../../coreclr/md/inc
${PROJECT_SOURCE_DIR}/../../coreclr/md/compiler)

set(mscorbi_sources_base
cordb.cpp
cordb.h
cordb-appdomain.cpp
cordb-appdomain.h
cordb-assembly.cpp
cordb-assembly.h
cordb-blocking-obj.cpp
cordb-blocking-obj.h
cordb-breakpoint.cpp
cordb-breakpoint.h
cordb-chain.cpp
cordb-chain.h
cordb-class.cpp
cordb-class.h
cordb-code.cpp
cordb-code.h
cordb-eval.cpp
cordb-eval.h
cordb-frame.cpp
cordb-frame.h
cordb-function.cpp
cordb-function.h
cordb-process.cpp
cordb-process.h
cordb-register.cpp
cordb-register.h
cordb-stepper.cpp
cordb-stepper.h
cordb-thread.cpp
cordb-thread.h
cordb-type.cpp
cordb-type.h
cordb-value.cpp
cordb-value.h
)


if(HOST_DARWIN)
set(OS_LIBS "-framework CoreFoundation" "-framework Foundation")
elseif(HOST_LINUX)
set(OS_LIBS pthread m dl)
elseif(HOST_WIN32)
set(OS_LIBS bcrypt.lib Mswsock.lib ws2_32.lib psapi.lib version.lib advapi32.lib winmm.lib kernel32.lib)
endif()

addprefix(mscorbi_sources ../dbi/ "${mscorbi_sources_base}")
add_subdirectory(${PROJECT_SOURCE_DIR}/socket-dbi)

include(${PROJECT_SOURCE_DIR}/../../../eng/native/configuretools.cmake)
include(${PROJECT_SOURCE_DIR}/../../../eng/native/configurepaths.cmake)
include(${PROJECT_SOURCE_DIR}/../../../eng/native/configureplatform.cmake)
include(${PROJECT_SOURCE_DIR}/../../../eng/native/configurecompiler.cmake)

if (CLR_CMAKE_HOST_UNIX)
include_directories("${PROJECT_SOURCE_DIR}/../../coreclr/pal/inc")
include_directories("${PROJECT_SOURCE_DIR}/../../coreclr/pal/inc/rt")
include_directories("${PROJECT_SOURCE_DIR}/../../coreclr/pal/src/safecrt")

append("-Wno-missing-prototypes -Wno-pointer-arith -Wno-macro-redefined" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
add_subdirectory(${PROJECT_SOURCE_DIR}/../../coreclr/pal pal)

include_directories("../../coreclr/pal/inc/rt/cpp")
add_compile_options(-nostdinc)
endif (CLR_CMAKE_HOST_UNIX)

include_directories("../../coreclr/pal/prebuilt/inc")
include_directories("../../coreclr/nativeresources")

if (CLR_CMAKE_HOST_UNIX)
add_subdirectory(${PROJECT_SOURCE_DIR}/../../coreclr/nativeresources nativeresources)
endif()

add_subdirectory(${PROJECT_SOURCE_DIR}/../../coreclr/md/runtime md/runtime)
add_subdirectory(${PROJECT_SOURCE_DIR}/../../coreclr/md/compiler md/compiler)

include(${PROJECT_SOURCE_DIR}/../../coreclr/clrdefinitions.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../inc/)
add_subdirectory(${PROJECT_SOURCE_DIR}/../../coreclr/md/enc md/enc)
add_subdirectory(${PROJECT_SOURCE_DIR}/../../coreclr/utilcode utilcode)
if (CLR_CMAKE_HOST_UNIX)
add_subdirectory(${PROJECT_SOURCE_DIR}/../../coreclr/palrt palrt)
append("-Wno-strict-prototypes -Wno-deprecated -Wno-pointer-arith" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif (CLR_CMAKE_HOST_UNIX)

add_library(mscordbi SHARED "${mscorbi_sources};${PROJECT_SOURCE_DIR}/../mono/mini/debugger-protocol.c;${PROJECT_SOURCE_DIR}/../../coreclr/pal/prebuilt/idl/xcordebug_i.cpp;${PROJECT_SOURCE_DIR}/../../coreclr/pal/prebuilt/idl/cordebug_i.cpp")

#SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})

set_source_files_properties(${PROJECT_SOURCE_DIR}/../mono/mini/debugger-protocol.c PROPERTIES LANGUAGE CXX)

set(COREDBI_LIBRARIES
utilcodestaticnohost
mdruntime-dbi
mdcompiler-dbi
mdruntimerw-dbi
socket-dbi
${OS_LIBS}
)

if(CLR_CMAKE_HOST_UNIX)
list(APPEND COREDBI_LIBRARIES
coreclrpal
palrt
nativeresourcestring
)
endif()

target_link_libraries(mscordbi ${COREDBI_LIBRARIES} )
install(TARGETS mscordbi DESTINATION lib)
Loading

0 comments on commit fe8bc17

Please sign in to comment.