Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn
On linux everything works properly out of the box, i tested with 
gdb and i can inspect globals


More info + linux dump on my comment: 
https://github.com/microsoft/vscode-cpptools/issues/10751#issuecomment-1487694435


So it's a problem either with msvc, or the way dmd/ldc write 
information for the linker?


Anyways..

linux: working out of the box

Windows: poop

Not a good outlook, then we wonder why people move away, 
debugging is essential


Am i the only want who want to improve things, is it a lost cause?

Should i move on?


Re: How can I restrict a library to be only included under a certain OS?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 21:10:08 UTC, solidstate1991 wrote:

I added this line to my SDLang formatted dub build file:

```
dependency "libx11" version="0.0.1" platform="posix"
```

Yet it's included even on Windows, even if I change it to 
"linux".


Since there's a fatal bug in the library that disallows it to 
be built, I'll be leaving it out for now, and instead move onto 
something else, or try to issue a correction.


I think the way to go is with configuration

``dub build`` // will default to config "posix" since it's the 
1st one
``dub build -c windows`` // will use "windows" config, without 
the dependency


https://dub.pm/package-format-sdl.html#configurations

```
configuration "posix" {
dependency "libx11" version="0.0.1"
}
configuration "windows" {
platforms "windows"
}
```

My dub knowledge is pretty limited, maybe there is a better way?


How can I restrict a library to be only included under a certain OS?

2023-03-28 Thread solidstate1991 via Digitalmars-d-learn

I added this line to my SDLang formatted dub build file:

```
dependency "libx11" version="0.0.1" platform="posix"
```

Yet it's included even on Windows, even if I change it to "linux".

Since there's a fatal bug in the library that disallows it to be 
built, I'll be leaving it out for now, and instead move onto 
something else, or try to issue a correction.


Re: Step by step tutorials for using bindings in D

2023-03-28 Thread eXodiquas via Digitalmars-d-learn

On Monday, 27 March 2023 at 00:06:36 UTC, Inkrementator wrote:
I'm surprised this worked, according to `man ld`, the -L flag 
takes a dir as input, not a full filepath. Can you please post 
your full dub config? I'm intrigued.


Hello again and thank you very much. I got it now, I got OpenGL, 
ncurses, Lua and Imgui running. This is amazing.


My dub.json file looked like this:

```json
{
"authors": [
"eXodiquas"
],
"copyright": "Copyright © 2023, eXodiquas",
"dependencies": {
"bindbc-lua": "~>1.0.0"
},
"lflags": ["-L/usr/local/lib/liblua.a"],
"versions": ["LUA_53"],
"description": "A minimal D application.",
"license": "proprietary",
"name": "test"
}
```

And I don't know what I did last time but this does not work, 
like you said. Maybe I forgot to save and was a bit stupid.


```json
{
"authors": [
"eXodiquas"
],
"copyright": "Copyright © 2023, eXodiquas",
"dependencies": {
"bindbc-lua": "~>0.5.1"
},
"description": "A minimal D application.",
"libs": ["lua"],
"license": "proprietary",
"name": "test",
"versions": [
"LUA_53"
]
}
```

This is working as it is supposed to do.

Thanks again for your time!


Re: Segfault with std.variant

2023-03-28 Thread Mitchell via Digitalmars-d-learn

Great! Thank you!


Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 14:02:39 UTC, ryuukk_ wrote:
Ready to test folder: 
https://github.com/microsoft/vscode-cpptools/issues/10751#issuecomment-1486948783


Contains simple source to reproduce the issue + build script

Also contains binaries + dump in case you just want to see the 
data


Hopefully we can figure that out


I noticed in the pdb, there are no mention of the ``app_d`` module


I can only find:

```
  40 | S_PROCREF [size = 28] `app_d.main`
   module = 1, sum name = 0, offset = 40
```

and

```
   0 | S_GDATA32 [size = 40] `app_d.notice_me_global`
   type = 0x0074 (int), addr = 0003:3504
```

Is that why the debugger can't inspect global variables?

Why doesn't the pdb contain anything about ``app_d``?




Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn
Ready to test folder: 
https://github.com/microsoft/vscode-cpptools/issues/10751#issuecomment-1486948783


Contains simple source to reproduce the issue + build script

Also contains binaries + dump in case you just want to see the 
data


Hopefully we can figure that out


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 13:18:59 UTC, Kagamin wrote:
This guid is (int,short,short,byte[8]) in little endian byte 
order. So if you want to convert it to big endian, you'll need 
to swap bytes in those int and two shorts.

```
ubyte[] guid=...
int* g1=cast(int*)guid.ptr;
*g1=bswap(*g1);
```


Yes, therefore, my option remains more correct rather than 
directly converting to UUID, since it does not correspond to the 
value specified in LDAP. Therefore, it is necessary to do byte 
permutations.


Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn

C program:

```C
int notice_me_global = -1;

void main()
{
notice_me_global = -5;
}
```

``cl app_c.c  /DEBUG /Zi /EHsc /std:c11 /link /DEBUG 
/out:app_c.exe``


``llvm-pdbutil.exe dump --globals app_c.pdb > dump_c``

```
  688476 | S_GDATA32 [size = 32] `notice_me_global`
   type = 0x0074 (int), addr = 0003:0040
```






D program:

```D
__gshared int notice_me_global = -1;

extern(C) void main()
{
notice_me_global = 5;
int* a;
*a = 1;
}
```

``dmd -betterC -m64 -g -debug app_d.d``

``llvm-pdbutil.exe dump --globals app_d.pdb > dump_d``

```
   0 | S_GDATA32 [size = 40] `app_d.notice_me_global`
   type = 0x0074 (int), addr = 0003:3504
```



Open question:


Why is it:

For D: ``0 |``
For C: ``688476 |``


Potential issue:

Debugger doesn't understand: the ``.`` in the name 
``app_d.notice_me_global``, mangled name also doesn't work


That's the info i provided in the microsoft tracker, maybe some 
people here can notice something else that's wrong



dump_c: 
https://gist.github.com/ryuukk/40c6d7d1cd3d6a010242d505380fe233
dump_d: 
https://gist.github.com/ryuukk/38f43383025907a8f44049503887206c


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/28/23 6:36 AM, WebFreak001 wrote:


the formatting messed up here. Try this code:

```d
auto uuid = UUID(
     (cast(const(ubyte)[]) value.attributes["objectGUID"][0])
     [0 .. 16]
);
```


Nice, I didn't think this would work actually!

-Steve


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/28/23 1:05 AM, Alexander Zhirov wrote:

On Tuesday, 28 March 2023 at 00:51:43 UTC, Steven Schveighoffer wrote:

`auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr);` (added quotes here)


```d
ubyte[] arr = cast(ubyte[])value.attributes["objectGUID"][0].dup;
writeln(UUID(cast(ubyte[16])arr.ptr));
```

`Error: cannot cast expression 'cast(ubyte*)arr' of type 'ubyte*' to 
'ubyte[16]'`


No, it's not possible to transform. The array is initially 
`immutable(char[])`.




Apologies, I quoted my original above to suppress the markdown 
formatting. Here it is again with syntax highlighting.


```d
auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr);
```

That should work. I sometimes forget that my newsreader adds the 
markdown tag, even though it looks good on my end.


-Steve


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Kagamin via Digitalmars-d-learn
This guid is (int,short,short,byte[8]) in little endian byte 
order. So if you want to convert it to big endian, you'll need to 
swap bytes in those int and two shorts.

```
ubyte[] guid=...
int* g1=cast(int*)guid.ptr;
*g1=bswap(*g1);
```


Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn
I opened an issue on microsoft's github, let's see what they have 
to say: https://github.com/microsoft/vscode-cpptools/issues/10751


Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 11:07:02 UTC, ryuukk_ wrote:
On Tuesday, 28 March 2023 at 04:22:24 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

On 28/03/2023 2:25 PM, ryuukk_ wrote:
On Tuesday, 28 March 2023 at 01:06:50 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

Have you tried installing mago?

https://github.com/rainers/mago

There are instructions for vs-code in README.


I did not try mago, but it shouldn't be needed as pdb is 
universally understood by tools


Agreed, I would expect globals (including TLS) to work without 
a debugger extension.


While i will try with mago, it shouldn't satisfy us, 
workarounds are temporary solutions


Its not a workaround, mago (in this case) is an extension to 
MS's debugger framework which provides D specific features, 
you'd want it regardless if you work with the debugger with D 
a lot. Debuggers typically have language specific features to 
make them easier to work with.


Jan should be shipping this I think.


It is a workaround, it should work already out of the box with 
existing tools


It works for other languages, why not for D? problem

Check here:

https://godbolt.org/z/nYGfMTqYY


int global; on C++ has !dbg

int global; on D doesn't have !dbg

This is a bug in D, therefore it should be fixed


Nevermind the godbolt link



Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 04:22:24 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

On 28/03/2023 2:25 PM, ryuukk_ wrote:
On Tuesday, 28 March 2023 at 01:06:50 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

Have you tried installing mago?

https://github.com/rainers/mago

There are instructions for vs-code in README.


I did not try mago, but it shouldn't be needed as pdb is 
universally understood by tools


Agreed, I would expect globals (including TLS) to work without 
a debugger extension.


While i will try with mago, it shouldn't satisfy us, 
workarounds are temporary solutions


Its not a workaround, mago (in this case) is an extension to 
MS's debugger framework which provides D specific features, 
you'd want it regardless if you work with the debugger with D a 
lot. Debuggers typically have language specific features to 
make them easier to work with.


Jan should be shipping this I think.


It is a workaround, it should work already out of the box with 
existing tools


It works for other languages, why not for D? problem

Check here:

https://godbolt.org/z/nYGfMTqYY


int global; on C++ has !dbg

int global; on D doesn't have !dbg

This is a bug in D, therefore it should be fixed


Re: Convert binary to UUID from LDAP

2023-03-28 Thread WebFreak001 via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 05:05:58 UTC, Alexander Zhirov wrote:
On Tuesday, 28 March 2023 at 00:51:43 UTC, Steven Schveighoffer 
wrote:

auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr);


```d
ubyte[] arr = 
cast(ubyte[])value.attributes["objectGUID"][0].dup;

writeln(UUID(cast(ubyte[16])arr.ptr));
```

`Error: cannot cast expression 'cast(ubyte*)arr' of type 
'ubyte*' to 'ubyte[16]'`


No, it's not possible to transform. The array is initially 
`immutable(char[])`.


the formatting messed up here. Try this code:

```d
auto uuid = UUID(
(cast(const(ubyte)[]) value.attributes["objectGUID"][0])
[0 .. 16]
);
```

no need to `.dup` the values - UUID can work without manipulating 
the original data, so we just need to cast the 
`immutable(char)[]` to `const(ubyte)[]`


The LDAP library should probably really instead expose `ubyte[]` 
instead of `string`


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Jacob Shtokolov via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 05:05:58 UTC, Alexander Zhirov wrote:
`Error: cannot cast expression 'cast(ubyte*)arr' of type 
'ubyte*' to 'ubyte[16]'`


Here is the working example:

```d
import std.stdio;
import std.uuid;

void main()
{
	ubyte[] arr = [159, 199, 22, 163, 13, 74, 145, 73, 158, 112, 7, 
192, 12, 193, 7, 194];

UUID(arr[0 .. 16]).writeln;
}
```
You just need to take a slice of your array to guarantee that it 
has only 16 elements, and thus, pass it to `UUID`.




Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 04:22:24 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

On 28/03/2023 2:25 PM, ryuukk_ wrote:
On Tuesday, 28 March 2023 at 01:06:50 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

Have you tried installing mago?

https://github.com/rainers/mago

There are instructions for vs-code in README.


I did not try mago, but it shouldn't be needed as pdb is 
universally understood by tools


Agreed, I would expect globals (including TLS) to work without 
a debugger extension.


While i will try with mago, it shouldn't satisfy us, 
workarounds are temporary solutions


Its not a workaround, mago (in this case) is an extension to 
MS's debugger framework which provides D specific features, 
you'd want it regardless if you work with the debugger with D a 
lot. Debuggers typically have language specific features to 
make them easier to work with.


Jan should be shipping this I think.


I have looked into trying to get mago to work so far, but didn't 
have any working state yet, which is why that is currently stuck. 
(+ I don't personally use Windows for development, so I don't 
have much usage experience for code-d / debugging integration, 
outside when I actively develop Windows fixes on it)


If you get mago to work with vscode feel free to tell me how you 
did it so we can add a debug configuration preset for code-d 
users / other users who want to manually use it.


Re: How to debug and watch globals in windows debugger?

2023-03-28 Thread WebFreak001 via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 01:04:19 UTC, ryuukk_ wrote:
I've now waste an entire day trying to figure out what's wrong, 
perhaps trusted D for my projects was a bad idea, i now look 
like a fool


sorry to hear that, I haven't really been looking to much into 
the debugging problems here yet. My extension mostly just 
integrates the existing tools here (Visual Studio Debugger / GDB 
+ whatever is emitted in the pdb files)


What I was talking about is that it's possible dmd didn't emit 
the globals information in any way that the GDB / Visual Studio 
Debugger understand right now. I'm not a debugger expert myself, 
looking into this is probably something that would take a bit of 
research about the DWARF / PDB formats and checking how DMD / LDC 
emit it. I think you can probably get some great help here from 
Martin Kinkelin. (I think the windows and linux debug info 
emission works differently / are different modules, so there 
might be discrepancies here)


I can help you point towards where to check and who to ask here, 
but I don't think I can help you actually solve this issue right 
now. I haven't really been focusing too much on the debugger, 
especially not on the implementation of debug symbol emissions 
and the debugger itself. I have only been adding a few scripts 
here to get the best out the debugger that we currently have. 
More things require more investment into actually improving the 
project.


I'm quite glad about your contributions you have been doing so 
far and I think the issues you are opening are good to find stuff 
to work on. (the DCD PRs you have open right now are very nice 
and appreciated, but need a bit of work still done to them before 
they can be merged. I have reviewed them, but didn't have time to 
actually make the changes and test them yet - if you want to get 
these changes in faster you can also implement or reply to my 
review comments)


Further people you could ask about here:
- Iain Buclaw (GDC developer), can probably tell you about what 
gcc does here and possibly has insights into the D backend code 
that generates debug info

- Martin Kinkelin (LDC developer), ditto
- Luís Ferreira (ljmf00 on discord) - has been working on LLDB 
for SAoC and implementing a bunch of things - if things are 
missing on the debugger side, he can probably help you with LLDB 
implementations (you probably only need to go this far if we want 
to add support for new custom data structure things that D has - 
most things can already be realized with the debug symbols)


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 08:15:03 UTC, Alexander Zhirov wrote:

So far it has been possible to convert like this



The idea was borrowed from 
[here](https://elixirforum.com/t/using-active-directory-guid-with-ecto-uuid-field/15904).


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Tuesday, 28 March 2023 at 05:26:08 UTC, Alexander Zhirov wrote:
When converting to HEX, I get the string 
`121F4C264DED5E41A33F445B0A1CAE32`, in which some values are 
reversed. I found ways on the Internet to transform the 
permutation method into the desired result, but most likely it 
will be a crutch rather than the right solution to lead to the 
final result `264c1f12-ed4d-415e-a33f-445b0a1cae32`.


So far it has been possible to convert like this

```d
{
writeln(value.attributes["objectGUID"][0].toUUID);
}

UUID toUUID(const char[] objectGUID)
{
if(objectGUID.length != 16)
throw new Exception("objectGUID does not match the 
length");


auto arr = (cast(ubyte[])objectGUID).array;

auto part1 = arr[0 .. 4].reverse;
auto part2 = arr[4 .. 6].reverse;
auto part3 = arr[6 .. 8].reverse;
auto part4 = arr[8 .. 10];
auto part5 = arr[10 .. $];

string hex =
toHexString(part1) ~ '-' ~
toHexString(part2) ~ '-' ~
toHexString(part3) ~ '-' ~
toHexString(part4) ~ '-' ~
toHexString(part5);

return cast(UUID)hex;
}
```


Re: Convert binary to UUID from LDAP

2023-03-28 Thread Kagamin via Digitalmars-d-learn
This guid is (int,short,short,byte[8]) in little endian byte 
order. So if you want to convert it to big endian, you'll need to 
swap bytes in those int and two shorts.

```
ubyte[] guid=...
int* g1=cast(int*)guid.ptr;
*g1=bswap(*g1);
```