Samsung / netcoredbg

NetCoreDbg is a managed code debugger with MI interface for CoreCLR.
MIT License
825 stars 104 forks source link

Error: 0x80070005: Access is denied. #90

Closed ppebb closed 2 years ago

ppebb commented 2 years ago
36656.134 I/NETCOREDBG(P594515, T594515): main.cpp: main(418) > Netcoredbg started
36656.134 I/NETCOREDBG(P594515, T594515): main.cpp: instantiate_protocol(118) > Creating protocol CLIProtocol
36656.135 I/NETCOREDBG(P594515, T594515): main.cpp: main(455) > pidDebugee 0
36656.135 I/NETCOREDBG(P594515, T594516): ioredirect.cpp: worker(164) > worker started
36657.628 E/NETCOREDBG(P594515, T594515): manageddebugger.cpp: operator(653) > m_dbgshim.CreateProcessForLaunch(reinterpret_cast<LPWSTR>(const_cast<WCHAR*>(to_utf16(ss.str()).c_str())), TRUE, outEnv.empty() ? NULL : &outEnv[0], m_cwd.empty() ? NULL : reinterpret_cast<LPCWSTR>(to_utf16(m_cwd).c_str()), &m_processId, &resumeHandle) : 0x80070005
36657.628 E/NETCOREDBG(P594515, T594516): ioredirect.cpp: ProcessFinishedReadRequests(342) > child process stdout/stderr reading error
36657.628 I/NETCOREDBG(P594515, T594516): ioredirect.cpp: operator(154) > IORedirectHelper::worker: terminated

These are the entire logs. The command I used to start debugging was netcoredbg --interpreter=cli -- dotnet tModLoader.dll. All of the permissions for any files it would be looking at are set properly, and it doesn't even work with root so I'm not sure could be wrong. I can provide any additional information if needed

viewizard commented 2 years ago

Note, for CoreCLR native code 0x80070005 is not only E_ACCESSDENIED but also could be COR_E_UNAUTHORIZEDACCESS: https://github.com/dotnet/runtime/blob/ed41478a0b16210901eb9067730b2f91966fd1d2/src/coreclr/pal/prebuilt/inc/corerror.h#L405

I could not help you too much in this case, since you receive this error code directly from CoreCLR public API, not from debugger inself: https://github.com/dotnet/runtime/blob/ed41478a0b16210901eb9067730b2f91966fd1d2/src/coreclr/dlls/dbgshim/dbgshim.cpp#L81

Just note, you issue related to process start by CoreCLR, you could try:

ppebb commented 2 years ago

dotnet tModLoader.dll works fine, using the absolute path doesn't change anything. https://paste.ppeb.me/uqaqefelam.yaml here are the full strace logs though. I've read through them and can't really figure anything out.

viewizard commented 2 years ago

dotnet tModLoader.dll works fine, using the absolute path doesn't change anything.

Let me think, that by some reason, CreateProcessForLaunch can't fork/exec... https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/debugging/createprocessforlaunch-function looks like Return Value section here is wrong.

https://paste.ppeb.me/uqaqefelam.yaml here are the full strace logs though. I've read through them and can't really figure anything out.

I can't open https://paste.ppeb.me/uqaqefelam.yaml, see only ERR_CONNECTION_TIMED_OUT.

Are you using SELinux/SMACK/AppArmor in your distro? Please, provide dmesg output right aftrer you have this error.

ppebb commented 2 years ago
strace: Process 20367 attached
read(0, "r", 1)                         = 1
write(1, "r", 1)                        = 1
read(0, "u", 1)                         = 1
write(1, "u", 1)                        = 1
read(0, "n", 1)                         = 1
write(1, "n", 1)                        = 1
read(0, "\r", 1)                        = 1
write(1, "\33[7G\33[J", 7)              = 7
write(1, "run", 3)                      = 3
write(1, "\33[10G", 5)                  = 5
ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0
write(1, "\n", 1)                       = 1
rt_sigaction(SIGINT, {sa_handler=SIG_IGN, sa_mask=[INT], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f2969b5f560}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
dup(0)                                  = 13
dup2(3, 0)                              = 0
dup(1)                                  = 14
dup2(6, 1)                              = 1
dup(2)                                  = 15
dup2(8, 2)                              = 2
gettid()                                = 20367
getpid()                                = 20367
getsid(20367)                           = 8373
statfs("/sys/fs/cgroup", {f_type=CGROUP2_SUPER_MAGIC, f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0, 0]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_NOSUID|ST_NODEV|ST_NOEXEC|ST_RELATIME}) = 0
openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 16
newfstatat(16, "", {st_mode=S_IFREG|0444, st_size=0, ...}, AT_EMPTY_PATH) = 0
brk(0x55dcefa2b000)                     = 0x55dcefa2b000
read(16, "22 27 0:21 / /proc rw,nosuid,nod"..., 1024) = 1024
read(16, "rw,nosuid,nodev,noexec,relatime "..., 1024) = 1024
read(16, ",relatime shared:45 - vfat /dev/"..., 1024) = 522
read(16, "", 1024)                      = 0
close(16)                               = 0
openat(AT_FDCWD, "/proc/self/cgroup", O_RDONLY) = 16
newfstatat(16, "", {st_mode=S_IFREG|0444, st_size=0, ...}, AT_EMPTY_PATH) = 0
read(16, "0::/user.slice/user-1000.slice/s"..., 1024) = 47
close(16)                               = 0
openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 16
newfstatat(16, "", {st_mode=S_IFREG|0444, st_size=0, ...}, AT_EMPTY_PATH) = 0
read(16, "22 27 0:21 / /proc rw,nosuid,nod"..., 1024) = 1024
read(16, "rw,nosuid,nodev,noexec,relatime "..., 1024) = 1024
read(16, ",relatime shared:45 - vfat /dev/"..., 1024) = 522
read(16, "", 1024)                      = 0
close(16)                               = 0
openat(AT_FDCWD, "/proc/self/cgroup", O_RDONLY) = 16
newfstatat(16, "", {st_mode=S_IFREG|0444, st_size=0, ...}, AT_EMPTY_PATH) = 0
read(16, "0::/user.slice/user-1000.slice/s"..., 1024) = 47
close(16)                               = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=512*1024}) = 0
prlimit64(0, RLIMIT_NOFILE, {rlim_cur=512*1024, rlim_max=512*1024}, NULL) = 0
pipe2([16, 17], O_CLOEXEC)              = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f2969b5f560}, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f2969b5f560}, 8) = 0
openat(AT_FDCWD, "/sys/devices/system/node/possible", O_RDONLY|O_CLOEXEC) = 18
read(18, "0\n", 32)                     = 2
close(18)                               = 0
access("./dotnet", R_OK)                = 0
access("./dotnet", F_OK)                = 0
stat("./dotnet", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
close(3)                                = 0
close(6)                                = 0
close(8)                                = 0
dup2(13, 0)                             = 0
close(13)                               = 0
dup2(14, 1)                             = 1
close(14)                               = 0
dup2(15, 2)                             = 2
close(15)                               = 0
write(1, "\33[31m Error: 0x80070005:  Access"..., 48) = 48
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=70, ws_col=283, ws_xpixel=2548, ws_ypixel=1409}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost -isig -icanon -echo ...}) = 0
write(1, "\33[1m\33[32mncdb>\33[0m ", 19) = 19
read(0, "q", 1)                         = 1
write(1, "q", 1)                        = 1
read(0, "u", 1)                         = 1
write(1, "u", 1)                        = 1
read(0, "i", 1)                         = 1
write(1, "i", 1)                        = 1
read(0, "t", 1)                         = 1
write(1, "t", 1)                        = 1
read(0, "\r", 1)                        = 1
write(1, "\33[7G\33[J", 7)              = 7
write(1, "quit", 4)                     = 4
write(1, "\33[11G", 5)                  = 5
ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
write(1, "\n", 1)                       = 1
write(1, "^exit\n", 6)                  = 6
openat(AT_FDCWD, ".netcoredbg_hist", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 3
fcntl(3, F_GETFL)                       = 0x8001 (flags O_WRONLY|O_LARGEFILE)
newfstatat(3, "", {st_mode=S_IFREG|0600, st_size=0, ...}, AT_EMPTY_PATH) = 0
write(3, "run\nquit\nrun\nquit\nrun\nquit\nrun\nq"..., 66) = 66
close(3)                                = 0
close(0)                                = 0
close(1)                                = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f2969b5f560}, NULL, 8) = 0
exit_group(0)                           = ?
+++ exited with 0 +++

Not sure why the url didn't work but here it is. As for SELinux/SMACK/AppArmor, I can't think of why I'd have any of those since I'm just using arch and don't recall installing any of them (do note that netcoredbg works for other c# applications, this issue seems to be specific to this dll).

As for dmesg, nothing seems to be printing there related to the pid of netcoredbg. The pid of netcoredbg doesn't show there at all and the only messages there unrelated to boot are about usb devices.

viewizard commented 2 years ago

do note that netcoredbg works for other c# applications, this issue seems to be specific to this dll

Hmm, you didn't mentioned that you have issue with this dll only.

Another idea - CLI have specific work with terminal in order to work proper for all cases, just for test purposes try with MI/GDB: netcoredbg --interpreter=mi -- dotnet tModLoader.dll -exec-run - run -exec-continue - continue -gdb-exit - quit At least we will know, that your issue not related to CLI's manipulations with stdin/stdout/stderr.

ppebb commented 2 years ago

Running netcoredbg --interpreter=mi -- dotnet tModLoader.dll gives

-exec-run
^error,msg="Error: 0x80070005"

That's all it puts out.

viewizard commented 2 years ago

Could you please provide more info about your environment: CoreCLR runtime version (.Net SDK version), netcoredbg (did you downloaded it or built) - I need understand what CoreCLR version you have and what dbgshim (from what CoreCLR version you are using). Also, any chance you can attach to this issue your dll/json/pdb (no sources needed) that let me start it with dotnet?

I am at vacation till 11 May, but after that I could try to reproduce this issue at office (and I hope find out what is wrong and why dbgshim don't like this dll).

ppebb commented 2 years ago

My dotnet version is 6.0.102 My netcoredbg version is 2.0.0-58 (b3598e5, Release). I used the aur package so I believe it's built

The dll and pdb can be found here https://github.com/tModLoader/tModLoader/actions/runs/2288375060#artifacts=. The release build in the artifacts.

ppebb commented 2 years ago

For some reason, using the full path to dotnet worked just fine. Running netcoredbg --interpreter=cli -- /usr/bin/dotnet tModLoader.dll fixed it

viewizard commented 2 years ago

Hmm... are you have 2 dotnet in system? Could it use another dotnet by some reason?

ppebb commented 2 years ago

Oh no it's because there was a dotnet folder in the tModLoader folder. tModLoader's startup scripts install a new version of dotnet to a folder so that bug reports are all on the same dotnet version, deleting the folder fixes it.

viewizard commented 2 years ago

Solved issue - best issue. :-)