Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in winch_trace_back() : unw_getcontext() error: -1073785320 #67

Open
barracuda156 opened this issue Apr 20, 2023 · 9 comments
Open

Comments

@barracuda156
Copy link

Seems not to work on PPC:

R version 4.2.3 (2023-03-15) -- "Shortstop Beagle"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: powerpc-apple-darwin10.0.0d2 (32-bit)

> library(winch)
> 
> foo0 <- function() {
+   winch_call(bar0)
+ }
> 
> bar0 <- function() {
+   winch_call(baz0)
+ }
> 
> baz0 <- function() {
+   winch_trace_back()
+ }
> 
> if (winch_available()) {
+   foo0()
+ }
Error in winch_trace_back() : unw_getcontext() error: -1073785320
Calls: foo0 ... <Anonymous> -> winch_call -> <Anonymous> -> winch_trace_back
Execution halted
R version 4.2.3 (2023-03-15) -- "Shortstop Beagle"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: powerpc-apple-darwin10.0.0d2 (32-bit)

  Natural language support but running in an English locale

> pkgname <- "winch"
> source(file.path(R.home("share"), "R", "examples-header.R"))
> options(warn = 1)
> library('winch')
> 
> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv')
> base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv')
> cleanEx()
> nameEx("winch_available")
> ### * winch_available
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: winch_available
> ### Title: Are native tracebacks available?
> ### Aliases: winch_available
> 
> ### ** Examples
> 
> winch_available()
[1] TRUE
> 
> 
> 
> cleanEx()
> nameEx("winch_call")
> ### * winch_call
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: winch_call
> ### Title: Call an R function from native code
> ### Aliases: winch_call
> 
> ### ** Examples
> 
> foo <- function() {
+   winch_call(bar)
+ }
> 
> bar <- function() {
+   writeLines("Hi!")
+ }
> 
> foo()
Hi!
NULL
> 
> 
> 
> cleanEx()
> nameEx("winch_init_library")
> ### * winch_init_library
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: winch_init_library
> ### Title: Set library to collect symbols for native stack traces
> ### Aliases: winch_init_library
> 
> ### ** Examples
> 
> ## Don't show: 
> if (requireNamespace("rlang", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)({ # examplesIf
+ ## End(Don't show)
+ winch_init_library(getLoadedDLLs()[["rlang"]][["path"]])
+ ## Don't show: 
+ }) # examplesIf
> winch_init_library(getLoadedDLLs()[["rlang"]][["path"]])
> ## End(Don't show)
> 
> 
> 
> cleanEx()
> nameEx("winch_stop")
> ### * winch_stop
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: winch_stop
> ### Title: Raise an error from native code
> ### Aliases: winch_stop
> 
> ### ** Examples
> 
> try(winch_stop("Test"))
Error in winch_stop("Test") : winch_stop(): Test
> 
> 
> 
> cleanEx()
> nameEx("winch_trace_back")
> ### * winch_trace_back
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: winch_trace_back
> ### Title: Native stack trace
> ### Aliases: winch_trace_back
> 
> ### ** Examples
> 
> ## Don't show: 
> if (winch_available()) (if (getRversion() >= "3.4") withAutoprint else force)({ # examplesIf
+ ## End(Don't show)
+ winch_trace_back()
+ 
+ foo <- function() {
+   winch_call(bar)
+ }
+ 
+ bar <- function() {
+   winch_trace_back()
+ }
+ 
+ foo()
+ ## Don't show: 
+ }) # examplesIf
> winch_trace_back()
Error in winch_trace_back() : unw_getcontext() error: -1073785400
Calls: <Anonymous> ... source -> withVisible -> eval -> eval -> winch_trace_back
Execution halted

P. S. This error is independent of the fact that present macho.c code is missing two archs. I have tried both with unmodified version and with fixed source for macho.c, error is identical.

@krlmlr
Copy link
Member

krlmlr commented Apr 20, 2023

Thanks. Is this a new error, or a regression? Did winch 0.0.12 or earlier versions work?

@barracuda156
Copy link
Author

Thanks. Is this a new error, or a regression? Did winch 0.0.12 or earlier versions work?

Let me try to run 0.0.12, I will update in a few minutes.

@barracuda156
Copy link
Author

@krlmlr Looks like the same failure on 0.0.12:

* checking files in ‘vignettes’ ... WARNING
Files in the 'vignettes' directory but no files in 'inst/doc':
  ‘report.Rmd’
* checking examples ... ERROR
Running examples in ‘winch-Ex.R’ failed
The error most likely occurred in:

> ### Name: winch_trace_back
> ### Title: Native stack trace
> ### Aliases: winch_trace_back
> 
> ### ** Examples
> 
> ## Don't show: 
> if (winch_available()) (if (getRversion() >= "3.4") withAutoprint else force)({ # examplesIf
+ ## End(Don't show)
+ winch_trace_back()
+ 
+ foo <- function() {
+   winch_call(bar)
+ }
+ 
+ bar <- function() {
+   winch_trace_back()
+ }
+ 
+ foo()
+ ## Don't show: 
+ }) # examplesIf
> winch_trace_back()
Error in winch_trace_back() : unw_getcontext() error: -1073785400
Calls: <Anonymous> ... source -> withVisible -> eval -> eval -> winch_trace_back
Execution halted
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
  Running ‘example0.R’
 ERROR
Running the tests in ‘tests/example0.R’ failed.
Last 13 lines of output:
  > 
  > bar0 <- function() {
  +   winch_call(baz0)
  + }
  > 
  > baz0 <- function() {
  +   winch_trace_back()
  + }
  > 
  > if (winch_available()) {
  +   foo0()
  + }
  Error in winch_trace_back() : unw_getcontext() error: -1073785320
  Calls: foo0 ... <Anonymous> -> winch_call -> <Anonymous> -> winch_trace_back
  Execution halted

Maybe somewhere else PPC is missing, not only in macho.c? I have only tried to fix it there, borrowing from https://github.com/ianlancetaylor/libbacktrace
Is the arch should be defined elsewhere too but is not, that would explain the error.

P. S. This is the minimum that is required: ianlancetaylor/libbacktrace@753968c
But I am not sure if something else missing.

@krlmlr
Copy link
Member

krlmlr commented Apr 20, 2023

Thanks. I never actually tested on PPC, and I don't have the resources to investigate this.

Perhaps #65 could solve this? I have updated my fork, could you please copy over and run another test?

@barracuda156
Copy link
Author

@krlmlr I see that unw_getcontext is sitting inside libunwind define. There is no fallback, right? I have no idea if libunwind works correctly for ppc. It builds, yeah, but that is all we know.

@krlmlr
Copy link
Member

krlmlr commented Apr 20, 2023

Thanks. I have no idea either. Happy to review a PR if you can find a solution. Sorry I can't be of more help here.

@barracuda156
Copy link
Author

@iains Iain, if you got a minute, could you please update us whether libbacktrace should work on Darwin PPC? I saw that you have committed earlier to the source: ianlancetaylor/libbacktrace@753968c
Since then there were a number of updates to macho.c.

Here we got an R module which uses libbacktrace. And tests fail on PPC (both canonical 10.6.8 Rosetta and 10A190 alike). Functionality seems to also rely on libunwind – and I am not sure if it is supposed to work or not.

@iains
Copy link

iains commented Apr 20, 2023

libbacktrace should work:

  1. If DWARF < 5
  2. If there is a .dSYM for the executable
  3. Obviously if the exe is generated with debug

(so you have to use dsymutil to generate the .dSYM unless that is already done by the build)

I guess PPC might have bit-rotted with changes that have not been tested there yet (I have not had any Darwin-time recently and right now all effort is focussed on the GCC-13.1 and GCC-12.3 releases).

@barracuda156
Copy link
Author

This issue got buried under other, I just reran tests with the new R and gcc13, and it still fails (not to much of a surprise, just for the record):

R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: powerpc-apple-darwin10.0.0d2 (32-bit)

> library(winch)
> 
> foo0 <- function() {
+   winch_call(bar0)
+ }
> 
> bar0 <- function() {
+   winch_call(baz0)
+ }
> 
> baz0 <- function() {
+   winch_trace_back()
+ }
> 
> if (winch_available()) {
+   foo0()
+ }
Error in winch_trace_back() : unw_getcontext() error: -1073785224
Calls: foo0 ... <Anonymous> -> winch_call -> <Anonymous> -> winch_trace_back
Execution halted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants