Re: [go-nuts] How to use syscall.Syscall to call a C function accept/return a structure on Windows

2020-10-31 Thread aihui zhu
for example:

void D2D1MakeRotateMatrix(
  FLOAT angle,
  D2D1_POINT_2F center,
  D2D1_MATRIX_3X2_F *matrix
);
and a COM based function: D2D1_SIZE_F ID2D1Bitmap_GetSize();

On Saturday, October 31, 2020 at 11:40:59 PM UTC+8, Ian Lance Taylor wrote:
>
> On Sat, Oct 31, 2020 at 2:52 AM aihui zhu > 
> wrote: 
> > 
> > the syscall.Syscall function accept/return only uintptr, how should i 
> deal with structure? 
> > 
> > i'm asking this question is because that i want to avoid CGo and use 
> pure Go in my module. 
>
> What Windows function do you want to call, and what is the structure type? 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/eebb0188-fea8-4aba-8e6b-296e41b0da8co%40googlegroups.com.


[go-nuts] How to use syscall.Syscall to call a C function accept/return a structure on Windows

2020-10-31 Thread aihui zhu
the syscall.Syscall function accept/return only uintptr, how should i deal 
with structure?

i'm asking this question is because that i want to avoid CGo and use pure 
Go in my module.
thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2464afb1-5ddd-4eb1-ab33-d206c308dea7n%40googlegroups.com.


Re: [go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-02 Thread aihui zhu
thank you and yes, i'm trying to debug a SIGSEGV occurred in C code. 

i'm going changed my C code to some other way, since it's a bit difficult 
to retrieve the stack trace for debugging..
On Saturday, October 3, 2020 at 1:12:36 PM UTC+8 Kurtis Rader wrote:

> On Fri, Oct 2, 2020 at 9:49 PM aihui zhu  wrote:
>
>> .crash file is also acceptable for me, if it contains a stack trace.
>>
>
> No, it does not. At least not for me when running a trivial C program that 
> simply dereferences a NULL pointer. It does contain some information (e.g., 
> the contents of the CPU registers) that coule be useful in deducing the 
> state of the program but a macOS ".crash" file does not contain a stack 
> trace.
>
> The default Go behavior for reporting panics does output stack traces. 
> However, I have no idea what CGo does and would be surprised if a panic 
> from the "C" code resulted in a useful backtrace of that code written to 
> stdout/stderr. So the problem seems to be that you are melding Go and C 
> code on macOS, the C code is causing a fatal error (most likely a SIGSEGV), 
> and you're trying to find the bug in the C code. Yes?
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e5d4de0f-8e5e-409e-87db-4f56369fad57n%40googlegroups.com.


Re: [go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-02 Thread aihui zhu
.crash file is also acceptable for me, if it contains a stack trace.

On Saturday, October 3, 2020 at 12:41:58 PM UTC+8 ren...@ix.netcom.com 
wrote:

> A crash file is not a core dump. It does not contain a memory dump. 
>
> On Oct 2, 2020, at 11:36 PM, Kurtis Rader  wrote:
>
> 
>
> On Fri, Oct 2, 2020 at 9:23 PM aihui zhu  wrote:
>
>> I mean that is there any way to expose SIGSEGV to macOS system just like 
>> a pure C program, so that the system could generate .crash file 
>> automatically.
>> currently, seems that go itself catch the SIGSEGV signal, and prints go 
>> trace back, so it doesn't trigger system default behavior for SIGSEGV.
>>
>
> That is correct. And, no, there is no way for that to result in a core 
> dump unless you build a custom Go runtime that changes the behavior of the 
> "crash()" function in src/runtime/signal_unix.go. That is for the reason 
> explained in the doc string in that function: You would end up with a huge 
> core dump file that would probably take an hour or more to create. Do you 
> actually have enough disk space (> 128 GB free space) and are willing to 
> wait upwards of an hour for the core file to be created? If so then I, and 
> no doubt others, would be interested in hearing from you why letting Go 
> behave that way on macOS is sensible for 99% of people running Go programs 
> on macOS.
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>
> -- 
>
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts...@googlegroups.com.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD9-qWpfrHzo6SHspAfxbk7EymGmSbj2Wb4squ1iRur-hg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD9-qWpfrHzo6SHspAfxbk7EymGmSbj2Wb4squ1iRur-hg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d50f6a1e-6d77-4f4e-bfce-df108005de42n%40googlegroups.com.


Re: [go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-02 Thread aihui zhu
I mean that is there any way to expose SIGSEGV to macOS system just like a 
pure C program, so that the system could generate .crash file automatically.
currently, seems that go itself catch the SIGSEGV signal, and prints go 
trace back, so it doesn't trigger system default behavior for SIGSEGV.

please correct me if i'm wrong at something,  thank you.

On Saturday, October 3, 2020 at 10:53:51 AM UTC+8 Kurtis Rader wrote:

> On Fri, Oct 2, 2020 at 12:26 PM Ian Lance Taylor  wrote:
>
>> On Thu, Oct 1, 2020 at 10:44 PM aihui zhu  wrote:
>> >
>> > C program could generate a core dump file, my os is Big Sur beta.
>>
>> Thanks.
>>
>> I see now that for darwin-amd64 we do not generate core dumps.  Sorry
>> for forgetting about that.
>>
>> We have this comment:
>>
>> // OS X core dumps are linear dumps of the mapped memory,
>> // from the first virtual byte to the last, with zeros in the gaps.
>> // Because of the way we arrange the address space on 64-bit systems,
>> // this means the OS X core file will be >128 GB and even on a zippy
>> // workstation can take OS X well over an hour to write (uninterruptible).
>> // Save users from making that mistake.
>>
>> It may be worth investigating whether this is still a problem on
>> current macOS systems.  The comment in question is in
>> runtime/signal_unix.go.
>
>
> It  looks like this is still a problem on macOS (at least as of 10.15 
> Catalina). A trivial C program that does nothing more than
>
> char *p = 0;
> *p = 'x';
>
> results in a 2.1 GB core dump.
>
> It might be worth documenting this limitation in the 
> https://golang.org/pkg/runtime/ documentation. :-)
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/abb89f94-173d-49cf-a70b-5a76c0f1334bn%40googlegroups.com.


Re: [go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-02 Thread aihui zhu
thank you.  i see that there are also .crash file generated at 
~/Library/Logs/DiagnosticReports
```
➜  ~ ls Library/Logs/DiagnosticReports/a.out_2020-10-02-1337* -lh
-rw--- 1 zah _analyticsusers 22K Oct  2 13:37 
Library/Logs/DiagnosticReports/a.out_2020-10-02-133721_hac.crash
-rw--- 1 zah _analyticsusers 21K Oct  2 13:37 
Library/Logs/DiagnosticReports/a.out_2020-10-02-133751_hac.crash
```
could go generates .crash file?
On Saturday, October 3, 2020 at 3:26:13 AM UTC+8 Ian Lance Taylor wrote:

> On Thu, Oct 1, 2020 at 10:44 PM aihui zhu  wrote:
> >
> > C program could generate a core dump file, my os is Big Sur beta.
>
> Thanks.
>
> I see now that for darwin-amd64 we do not generate core dumps. Sorry
> for forgetting about that.
>
> We have this comment:
>
> // OS X core dumps are linear dumps of the mapped memory,
> // from the first virtual byte to the last, with zeros in the gaps.
> // Because of the way we arrange the address space on 64-bit systems,
> // this means the OS X core file will be >128 GB and even on a zippy
> // workstation can take OS X well over an hour to write (uninterruptible).
> // Save users from making that mistake.
>
> It may be worth investigating whether this is still a problem on
> current macOS systems. The comment in question is in
> runtime/signal_unix.go.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b6a77509-a810-4d1f-bf50-6dc3e1fc94d0n%40googlegroups.com.


Re: [go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-01 Thread aihui zhu
C program could generate a core dump file, my os is Big Sur beta.

➜  ~ ./a.out
[1]37539 segmentation fault  ./a.out
➜  ~ ulimit -c unlimited
➜  ~ ./a.out
[1]37596 segmentation fault (core dumped)  ./a.out
➜  ~ cat a.c
int main() {
int a = *((int*)(0));
return a;
}
➜  ~ ls /cores -lh
total 2.9G
-r 1 zah wheel 2.9G Oct  2 13:37 core.37596

On Friday, October 2, 2020 at 12:55:05 PM UTC+8 Ian Lance Taylor wrote:

> On Thu, Oct 1, 2020 at 9:05 PM Kurtis Rader  wrote:
> >
> > On Thu, Oct 1, 2020 at 8:36 PM aihui zhu  wrote:
> >>
> >> on a linux virtual machine GOTRACEBACK=crash works fine and would 
> generates core files in working directory for me.
> >
> >
> > I just tested this trivial Go (not CGo) program:
> >
> > package main
> > func main() {
> > panic("WTF")
> > }
> >
> >
> > I ran the above program on Linux distro OpenSuse 42. With the specified 
> env var results I get a core dump. The same action on macOS 10.15 
> (Catalina) only produces a backtrace -- no core dump. Looks like a bug (or 
> unimplemented feature) to me.
>
> Can you get a core dump from a C program on macOS 10.15?
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c5f02d22-5d0d-43fc-9ba5-874a69c325b0n%40googlegroups.com.


Re: [go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-01 Thread aihui zhu
on a linux virtual machine GOTRACEBACK=crash works fine and would generates 
core files in working directory for me.

On Friday, October 2, 2020 at 11:33:37 AM UTC+8 aihui zhu wrote:

> yes, there are only go stack trace, and no core file was generated. with a 
> pure C program, it could generate core file in /cores directory.
>
> On Friday, October 2, 2020 at 10:16:51 AM UTC+8 Ian Lance Taylor wrote:
>
>> On Thu, Oct 1, 2020 at 5:39 PM aihui zhu  wrote:
>> >
>> > I have enabled coredump with `ulimit -c unlimited`, and run the binary 
>> with GOTRACEBACK=crash, but it only outputs the go stack trace when crash.
>>
>> There are two different things. There is the stack trace emitted when
>> a program crash. And there is the core dump file generated by the
>> kernel when a program crashes (if GOTRACEBACK=crash is set). It is
>> normal for the stack trace to only show Go functions (though you could
>> try importing github.com/ianlancetaylor/cgosymbolizer). I'm not
>> clear: are you saying that you see only the stack trace, and that you
>> do not see a core dump file?
>>
>> Ian
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0dff70ce-ce35-442b-8937-b1755e5f93efn%40googlegroups.com.


Re: [go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-01 Thread aihui zhu
yes, there are only go stack trace, and no core file was generated. with a 
pure C program, it could generate core file in /cores directory.

On Friday, October 2, 2020 at 10:16:51 AM UTC+8 Ian Lance Taylor wrote:

> On Thu, Oct 1, 2020 at 5:39 PM aihui zhu  wrote:
> >
> > I have enabled coredump with `ulimit -c unlimited`, and run the binary 
> with GOTRACEBACK=crash, but it only outputs the go stack trace when crash.
>
> There are two different things. There is the stack trace emitted when
> a program crash. And there is the core dump file generated by the
> kernel when a program crashes (if GOTRACEBACK=crash is set). It is
> normal for the stack trace to only show Go functions (though you could
> try importing github.com/ianlancetaylor/cgosymbolizer). I'm not
> clear: are you saying that you see only the stack trace, and that you
> do not see a core dump file?
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3031c2ae-6900-41e3-aceb-73e9e3f7c85fn%40googlegroups.com.


[go-nuts] cgo: how to generate crash report/coredump on macOS for SIGSEGV

2020-10-01 Thread aihui zhu
I have enabled coredump with `ulimit -c unlimited`, and run the binary with 
GOTRACEBACK=crash, but it only outputs the go stack trace when crash. 

thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8a93e022-f9a2-4b12-9b1d-e50640dd5573n%40googlegroups.com.


[go-nuts] go module local development problem with replace directive in go.mod

2020-04-22 Thread aihui zhu
for example A deps B and B deps C
adds replace B => local/path/to/B in A/go.mod and replace C => 
local/path/to/C in B/go.mod
changes C doesn't rebuilds A.

it's it a bug or work as intend? 

how could i make rebuild works, otherwise i may need to create git commits, 
update A and B package again and again.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a21791a5-8cbe-406e-ae45-223d3eba727f%40googlegroups.com.


[go-nuts] How to use plugin package to do livereload?

2020-04-15 Thread aihui zhu
my program and plugin shares some common package, i'm temporarily copy the 
plugin's main package to main_$timestamp, 
so i can avoid same pluginpath and load it many times.

but it doesn't works for some problems:
if i changes only structure method, because of type equal, the runtime 
still refers to the old type, the new function will never be run.
if i change the structure members, the plugin was failed to load for error 
'plugin was built with a different version'

i'm thinking another way: could i change the plugin's module name to 
module_$timestamp before go build, so the plugin doesn't shares package 
with main program?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8a004129-e649-4d2a-a4a9-e20cbdd1858b%40googlegroups.com.


[go-nuts] Re: how could i embed harfbuzz library source into go package

2019-12-14 Thread aihui zhu
Problem solved, thanks.

I created a harfbuzz.cc inside the go package directory, it contains only 
one line

#include "harfbuzz/src/harfbuzz.cc"


and then change the cgo header to:

/*
#cgo CFLAGS: -Iharfbuzz/src
#cgo CXXFLAGS: -std=c++11
#cgo LDFLAGS: -lstdc++

#include 
#include "hb.h"

#include "hb-ot.h"

*/
import "C"



-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3126a3f3-2848-4a2b-9b8e-ddab40ca4b1c%40googlegroups.com.


[go-nuts] how could i embed harfbuzz library source into go package

2019-12-14 Thread aihui zhu
I'm trying to embed the harfbuzz(http://github.com/harfbuzz/harfbuzz) 
library source code into go package, 
just like what the glfw(http://github.com/go-gl/glfw) library does.
The difference is that glfw contains only C, but harfbuzz is actually a C++ 
library and provide C API.

My cgo header code is here:

/*
#cgo CFLAGS: -Iharfbuzz/src -std=c++11 -x c++
#cgo LDFLAGS: -lstdc++

#include 
#include "hb.h"
#include "hb-ot.h"
#include "harfbuzz.cc"
*/
import "C"


when i compile it, i got many errors like 
./harfbuzz.go:50:42: could not determine kind of name for C.char
./harfbuzz.go:373:20: could not determine kind of name for C.float
./harfbuzz.go:327:2: could not determine kind of name for C.free
./harfbuzz.go:97:9: could not determine kind of name for C.hb_blob_create
./harfbuzz.go:316:2: could not determine kind of name for C.hb_blob_destroy
./harfbuzz.go:325:11: could not determine kind of name for 
C.hb_blob_get_data
./harfbuzz.go:320:14: could not determine kind of name for 
C.hb_blob_get_length
./harfbuzz.go:87:84: could not determine kind of name for C.hb_blob_t

but there is no errors when i change the cgo header to use the dynamic 
library installed by Homebrew.

 I am not so familiar with Cgo/C++ compiling, could anyone help me.
Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/284d5720-8daa-4dd8-9733-80973d650e9b%40googlegroups.com.