Re: core file
On 11/12/2017 10:25 PM, Tony wrote: >>> "Segmentation fault (core dumped)" I've been assuming that if it says "dumped", the core is dumped. > I am on Ubuntu 16.04. Thanks, I didn't know that "producing a core file" > was configurable, and it appears that it isn't. It is. If you search for "where is core file ubuntu" you will hit the output of 'man core', as well as answers like the following, which explains that the file may be under /var/cache/abrt: https://stackoverflow.com/questions/2065912/core-dumped-but-core-file-is-not-in-current-directory Ali
Re: core file
On Monday, 13 November 2017 at 05:37:12 UTC, codephantom wrote: On Monday, 13 November 2017 at 05:01:18 UTC, Tony wrote: I am getting the message from my program execution: "Segmentation fault (core dumped)" But I don't see a core file in the current directory or in my home directory. Is there one somewhere? Would I be able to do anything meaningful with it if it exists? More info than that is needed. What platform are you on? Do you have core dumps enabled/disabled? If you have it enabled...where does it put them? And yes, core dumps are potentially useful for debugging. However, given you're asking that question, and getting core dumps, then it might be easier for you to use the -g option when you compile, and then run your executable (or a.out) through a debugger: https://www.youtube.com/watch?v=vcVmWbYEIsk I am on Ubuntu 16.04. Thanks, I didn't know that "producing a core file" was configurable, and it appears that it isn't.
Re: core file
On Monday, 13 November 2017 at 05:01:18 UTC, Tony wrote: I am getting the message from my program execution: "Segmentation fault (core dumped)" But I don't see a core file in the current directory or in my home directory. Is there one somewhere? Would I be able to do anything meaningful with it if it exists? More info than that is needed. What platform are you on? Do you have core dumps enabled/disabled? If you have it enabled...where does it put them? And yes, core dumps are potentially useful for debugging. However, given you're asking that question, and getting core dumps, then it might be easier for you to use the -g option when you compile, and then run your executable (or a.out) through a debugger: https://www.youtube.com/watch?v=vcVmWbYEIsk
core file
I am getting the message from my program execution: "Segmentation fault (core dumped)" But I don't see a core file in the current directory or in my home directory. Is there one somewhere? Would I be able to do anything meaningful with it if it exists?
Re: How do I create a fileWatcher with an onFileChange event using spawn?
On Friday, 25 August 2017 at 21:25:37 UTC, Enjoys Math wrote: Something like this: module file_watcher; import std.concurrency; import std.file; import std.signals; import std.datetime; void fileWatcher(Tid tid, string filename, int loopSleep) { auto modified0 = timeLastModified(filename); while (true) { modified = timeLastModified(filename); if (modified > modified0) { modified0 = modified; //if (onFileChange !is null) //onFileChange(receiver); } sleep(dur!"msecs"(loopSleep)); } } But I'm not sure how to send the onFiledChange event. @Nemanja Boric I would not recommend calling those APIs on Windows because they work on entire directories, not suitable for individual files and sometimes those functions not even work when other programs change the files in a non standard way (that has happened to me before when editing through a text editor) @Enjoys Math The way I usually deal with this problem is I save the filename, the time and handler function in an associative array and loop through when something changes, this way you can delete, sort, etc on the map when the files are deleted or so. Hope this helps a little.
Re: How do I use Socket.select?
On Sunday, 12 November 2017 at 21:45:56 UTC, Anonymouse wrote: But a "status change" for a reading Socket is "stuff can now connect", for a writing one "connection established", and not sure about the error ones. It doesn't seem to be "there's data waiting to be read" which I'd hoped for, since my program (IRC bot) in essence connects once and stays such throughout its life. What else is there to select that I'm missing? Or is it mostly a thing for programs with lots of Sockets, lots of connections? The read set is used to determine if a socket has data waiting to read. It just happens that with a listening socket, that means there's a new connection. With a normal socket, it means data packets are ready. Maybe you should take a look at the classic Beej's guide, which covers the C API. Should be easy to translate to the std.socket API. http://beej.us/guide/bgnet/
Re: opCast'ing strings
On Monday, 13 November 2017 at 01:03:17 UTC, helxi wrote: In this program, casting using to does not work as intended (returning 23/11) on the struct. However, calling opCast directly seems to do the job. Why is that? to!string calls a function called `string toString() {}` on the struct, not the cast operator.
opCast'ing strings
struct Fraction { private: int numerator = 1, denominator = 1; public: string opCast(T : string)() const { import std.conv : to; return numerator.to!string() ~ "/" ~ denominator.to!string(); } } void main() { import std.stdio, std.conv; Fraction n = Fraction(23, 11); writeln(n.to!string(), " ", n.opCast!string); } In this program, casting using to does not work as intended (returning 23/11) on the struct. However, calling opCast directly seems to do the job. Why is that?
Re: Inline assembly question
On Sunday, 12 November 2017 at 22:24:08 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 22:20:46 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 22:00:58 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 21:27:28 UTC, Dibyendu Majumdar I am not sure I have understood above; will DMD generate the right Win64 unwind info for this contrived example: no in naked mode you have to save and restore by hand. So how does one manually generate the .pdata and .xdata sections? Are you saying that this is what I would need to do? Another question - how can I tell DMD to no generate the frame pointer? Thanks for answering my questions. Regards Dibyendu
Re: Inline assembly question
On Sunday, 12 November 2017 at 22:00:58 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 21:27:28 UTC, Dibyendu Majumdar Does the compiler generate appropriate unwind information on Win64? Prsumably if a function is marked 'naked' then it doesn't? yeah about stack frame..., also don't forget to mark the asm block "pure nothrow" if possible... It's not documented but the syntax is like that: ``` void foo() { asm pure nothrow { naked; ret; } } ``` I am not sure I have understood above; will DMD generate the right Win64 unwind info for this contrived example: int luaV_interp(lua_State *L) { asm pure nothrow { naked; push RDI; push RSI; push RBX; push R12; push R13; push R14; push R15; sub RSP, 5*8; mov RAX, 0; add RSP, 5*8; pop R15; pop R14; pop R13; pop R12; pop RBX; pop RSI; pop RDI; pop RBP; ret; } }
Re: Inline assembly question
On Sunday, 12 November 2017 at 22:20:46 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 22:00:58 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 21:27:28 UTC, Dibyendu Majumdar I am not sure I have understood above; will DMD generate the right Win64 unwind info for this contrived example: no in naked mode you have to save and restore by hand.
Re: Inline assembly question
On Sunday, 12 November 2017 at 21:27:28 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 18:48:02 UTC, Eugene Wissner wrote: https://dlang.org/spec/iasm.html#agregate_member_offsets aggregate.member.offsetof[someregister] Sorry I didn't phrase my question accurately. Presumably to use above with the mnemonics I would need additional mixin templates where the aggregate type and member etc would need to be parameters? You can use just string parameters instead of enums, then you can pass arbitrary arguments to the instructions. The compiler will tell you if something is wrong with the syntax of the generated assembly. Okay thank you. Sigh. It would be so much simpler to be able to just define mnemonics for registers. Anyway, another question: Does the compiler generate appropriate unwind information on Win64? Prsumably if a function is marked 'naked' then it doesn't? Thanks and Regards Dibyendu yeah about stack frame..., also don't forget to mark the asm block "pure nothrow" if possible... It's not documented but the syntax is like that: ``` void foo() { asm pure nothrow { naked; ret; } } ```
How do I use Socket.select?
I've been using blocking Sockets with timeouts for a while now, but wherever I look the word is "do consider using a non-blocking socket". Even the docs for std.socket.setOption; In a typical application, you might also want to consider using a non-blocking socket instead of setting a timeout on a blocking one. So I'm trying to wrap my head around select but I can't get it to work in any way that's better than my current blocking reads. A SocketSet is a bundle of Sockets that you can add to and remove from, but you can't index. They're just there but out of reach. A call to Socket.select(SocketSet readers, SocketSet writers, SocketSet error) *blocks* (unless supplied a timeout), and when something happens returns a number telling you how many sockets changed status, but not which. The Sockets of those three SocketSets now magically disassociated themselves if they weren't one of those that changed status. You then have to call {readers,writers,error}.isSet(mySocket) and manually delve which one is still in there, and by extension, which one did change. But a "status change" for a reading Socket is "stuff can now connect", for a writing one "connection established", and not sure about the error ones. It doesn't seem to be "there's data waiting to be read" which I'd hoped for, since my program (IRC bot) in essence connects once and stays such throughout its life. What else is there to select that I'm missing? Or is it mostly a thing for programs with lots of Sockets, lots of connections?
Re: Inline assembly question
On Sunday, 12 November 2017 at 18:48:02 UTC, Eugene Wissner wrote: https://dlang.org/spec/iasm.html#agregate_member_offsets aggregate.member.offsetof[someregister] Sorry I didn't phrase my question accurately. Presumably to use above with the mnemonics I would need additional mixin templates where the aggregate type and member etc would need to be parameters? You can use just string parameters instead of enums, then you can pass arbitrary arguments to the instructions. The compiler will tell you if something is wrong with the syntax of the generated assembly. Okay thank you. Sigh. It would be so much simpler to be able to just define mnemonics for registers. Anyway, another question: Does the compiler generate appropriate unwind information on Win64? Prsumably if a function is marked 'naked' then it doesn't? Thanks and Regards Dibyendu
Re: Class allocators
On Sunday, 12 November 2017 at 20:41:03 UTC, Basile B. wrote: No, the classes and structs of the examples are simply declared as 'static' because they are located in a 'unittest' block. You can ignore the keyword...it just means that they are declared as if they would stand at the global scope. Thanks.
Re: Class allocators
On Sunday, 12 November 2017 at 18:46:54 UTC, Per Nordlöw wrote: On Sunday, 12 November 2017 at 18:34:42 UTC, Eduard Staniloiu wrote: On Saturday, 11 November 2017 at 14:26:34 UTC, Nordlöw wrote: Have anybody used allocators to construct class instances? I might be wrong, but I think you are looking for std.experimental.allocator.make [0] [0] - https://dlang.org/phobos/std_experimental_allocator.html#make Thanks! In the example the classes are declared as static. What effect does this have here and is it required for classes allocated via make? No, the classes and structs of the examples are simply declared as 'static' because they are located in a 'unittest' block. You can ignore the keyword...it just means that they are declared as if they would stand at the global scope.
Re: Inline assembly question
On Sunday, 12 November 2017 at 15:25:43 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 12:32:09 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 12:17:51 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 11:55:23 UTC, Eugene Wissner wrote: [...] Thank you - I probably could use something like this. It is uglier than the simpler approach in dynasm of course. How about when I need to combine this with some struct/union access? In dynasm I can write: | mov BASE, CI->u.l.base // BASE = ci->u.l.base (volatile) | mov PC, CI->u.l.savedpc// PC = CI->u.l.savedpc How can I mix the mixin above and combine with struct offsets? https://dlang.org/spec/iasm.html#agregate_member_offsets aggregate.member.offsetof[someregister] Sorry I didn't phrase my question accurately. Presumably to use above with the mnemonics I would need additional mixin templates where the aggregate type and member etc would need to be parameters? You can use just string parameters instead of enums, then you can pass arbitrary arguments to the instructions. The compiler will tell you if something is wrong with the syntax of the generated assembly.
Re: Class allocators
On Sunday, 12 November 2017 at 18:34:42 UTC, Eduard Staniloiu wrote: On Saturday, 11 November 2017 at 14:26:34 UTC, Nordlöw wrote: Have anybody used allocators to construct class instances? I might be wrong, but I think you are looking for std.experimental.allocator.make [0] [0] - https://dlang.org/phobos/std_experimental_allocator.html#make Thanks! In the example the classes are declared as static. What effect does this have here and is it required for classes allocated via make?
Re: Class allocators
On Saturday, 11 November 2017 at 14:26:34 UTC, Nordlöw wrote: Have anybody used allocators to construct class instances? I might be wrong, but I think you are looking for std.experimental.allocator.make [0] [0] - https://dlang.org/phobos/std_experimental_allocator.html#make
Re: Inline assembly question
On Sunday, 12 November 2017 at 12:32:09 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 12:17:51 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 11:55:23 UTC, Eugene Wissner wrote: [...] Thank you - I probably could use something like this. It is uglier than the simpler approach in dynasm of course. How about when I need to combine this with some struct/union access? In dynasm I can write: | mov BASE, CI->u.l.base // BASE = ci->u.l.base (volatile) | mov PC, CI->u.l.savedpc// PC = CI->u.l.savedpc How can I mix the mixin above and combine with struct offsets? https://dlang.org/spec/iasm.html#agregate_member_offsets aggregate.member.offsetof[someregister] Sorry I didn't phrase my question accurately. Presumably to use above with the mnemonics I would need additional mixin templates where the aggregate type and member etc would need to be parameters?
Re: Automatic insertion of D-style multiline-comments in Emacs
On Sunday, 12 November 2017 at 12:52:48 UTC, Nordlöw wrote: Have anybody added logic to Emacs' `comment-dwim` that automagically inserts a (Ddoc-style) multi-line comment like /** ... */ void foo { } if the cursor is currently in front of a (function) definition (or declaration)? I realize that the challenge here is context detection; perhaps `beginning-of-defun()` could be used? my IDE AST tool does this and even more (detection of parameters, return section and throw section): https://github.com/BBasile/Coedit/blob/master/dastworx/src/ddoc_template.d https://www.youtube.com/watch?v=VEVqSItCKfo=11=PLzk8A0LUvEOV-OMdz09jfOahwnKoA2na_ though you would need a bridge to interpret and use the output in Emacs.
Re: Automatic insertion of D-style multiline-comments in Emacs
On Sunday, 12 November 2017 at 12:52:48 UTC, Nordlöw wrote: Have anybody added logic to Emacs' `comment-dwim` that automagically inserts a (Ddoc-style) multi-line comment like Posted also here: https://stackoverflow.com/questions/47249052/automatic-insertion-of-multiline-declaration-comments
Automatic insertion of D-style multiline-comments in Emacs
Have anybody added logic to Emacs' `comment-dwim` that automagically inserts a (Ddoc-style) multi-line comment like /** ... */ void foo { } if the cursor is currently in front of a (function) definition (or declaration)? I realize that the challenge here is context detection; perhaps `beginning-of-defun()` could be used?
Re: Inline assembly question
On Sunday, 12 November 2017 at 12:17:51 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 11:55:23 UTC, Eugene Wissner wrote: [...] Thank you - I probably could use something like this. It is uglier than the simpler approach in dynasm of course. How about when I need to combine this with some struct/union access? In dynasm I can write: | mov BASE, CI->u.l.base // BASE = ci->u.l.base (volatile) | mov PC, CI->u.l.savedpc// PC = CI->u.l.savedpc How can I mix the mixin above and combine with struct offsets? Thanks and Regards Dibyendu https://dlang.org/spec/iasm.html#agregate_member_offsets aggregate.member.offsetof[someregister]
Re: Inline assembly question
On Sunday, 12 November 2017 at 11:55:23 UTC, Eugene Wissner wrote: On Sunday, 12 November 2017 at 11:01:39 UTC, Dibyendu Majumdar wrote: I have recently started work on building a VM for Lua (actually a derivative of Lua) in X86-64 assembly. I am using the dynasm tool that is part of LuaJIT. I was wondering whether I could also write this in D's inline assembly perhaps, but there is one aspect that I am not sure how to do. The assembly code uses static allocation of registers, but because of the differences in how registers are used in Win64 versus Unix X64 - different registers are assigned depending on the architecture. dynasm makes this easy to do using macros; e.g. below. |.if X64WIN |.define CARG1, rcx // x64/WIN64 C call arguments. |.define CARG2, rdx |.define CARG3, r8 |.define CARG4, r9 |.else |.define CARG1, rdi // x64/POSIX C call arguments. |.define CARG2, rsi |.define CARG3, rdx |.define CARG4, rcx |.endif With above in place, the code can use the mnemonics to refer to the registers rather than the registers themselves. This allows the assembly code to be coded once for both architectures. How would one do this in D inline assembly? Thanks and Regards Dibyendu Here is an example with mixins: version (Windows) { enum Reg : string { CARG1 = "RCX", CARG2 = "RDX", } } else { enum Reg : string { CARG1 = "RDI", CARG2 = "RSI", } } template Instruction(string I, Reg target, Reg source) { enum string Instruction = "asm { mov " ~ target ~ ", " ~ source ~ "; }"; } void func() { mixin(Instruction!("mov", Reg.CARG1, Reg.CARG2)); } Thank you - I probably could use something like this. It is uglier than the simpler approach in dynasm of course. How about when I need to combine this with some struct/union access? In dynasm I can write: | mov BASE, CI->u.l.base // BASE = ci->u.l.base (volatile) | mov PC, CI->u.l.savedpc// PC = CI->u.l.savedpc How can I mix the mixin above and combine with struct offsets? Thanks and Regards Dibyendu
Re: Inline assembly question
On Sunday, 12 November 2017 at 12:00:00 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 11:01:39 UTC, Dibyendu Majumdar wrote: [...] The assembly code uses static allocation of registers, but because of the differences in how registers are used in Win64 versus Unix X64 - different registers are assigned depending on the architecture. dynasm makes this easy to do using macros; e.g. below. [...] With above in place, the code can use the mnemonics to refer to the registers rather than the registers themselves. This allows the assembly code to be coded once for both architectures. I see...the problem is not the input parameters but functions calls **inside** iasm, right ? Not sure I understand the question. Once the defines are there I can write following: | // Call luaF_close | mov CARG1, L // arg1 = L | mov CARG2, BASE// arg2 = base | call extern luaF_close // call luaF_close As you can see above, CARG1, L, CARG2, BASE are all mnemonics that map to registers. However this is only defined in one place. Regards Dibyendu
Re: Inline assembly question
On Sunday, 12 November 2017 at 11:01:39 UTC, Dibyendu Majumdar wrote: Hi, I have recently started work on building a VM for Lua (actually a derivative of Lua) in X86-64 assembly. I am using the dynasm tool that is part of LuaJIT. I was wondering whether I could also write this in D's inline assembly perhaps, but there is one aspect that I am not sure how to do. The assembly code uses static allocation of registers, but because of the differences in how registers are used in Win64 versus Unix X64 - different registers are assigned depending on the architecture. dynasm makes this easy to do using macros; e.g. below. |.if X64WIN |.define CARG1, rcx // x64/WIN64 C call arguments. |.define CARG2, rdx |.define CARG3, r8 |.define CARG4, r9 |.else |.define CARG1, rdi // x64/POSIX C call arguments. |.define CARG2, rsi |.define CARG3, rdx |.define CARG4, rcx |.endif With above in place, the code can use the mnemonics to refer to the registers rather than the registers themselves. This allows the assembly code to be coded once for both architectures. How would one do this in D inline assembly? Thanks and Regards Dibyendu Here is an example with mixins: version (Windows) { enum Reg : string { CARG1 = "RCX", CARG2 = "RDX", } } else { enum Reg : string { CARG1 = "RDI", CARG2 = "RSI", } } template Instruction(string I, Reg target, Reg source) { enum string Instruction = "asm { mov " ~ target ~ ", " ~ source ~ "; }"; } void func() { mixin(Instruction!("mov", Reg.CARG1, Reg.CARG2)); }
Re: Inline assembly question
On Sunday, 12 November 2017 at 11:01:39 UTC, Dibyendu Majumdar wrote: Hi, [...] The assembly code uses static allocation of registers, but because of the differences in how registers are used in Win64 versus Unix X64 - different registers are assigned depending on the architecture. dynasm makes this easy to do using macros; e.g. below. [...] With above in place, the code can use the mnemonics to refer to the registers rather than the registers themselves. This allows the assembly code to be coded once for both architectures. I see...the problem is not the input parameters but functions calls **inside** iasm, right ?
Re: Inline assembly question
On Sunday, 12 November 2017 at 11:01:39 UTC, Dibyendu Majumdar wrote: Hi, I have recently started work on building a VM for Lua (actually a derivative of Lua) in X86-64 assembly. I am using the dynasm tool that is part of LuaJIT. I was wondering whether I could also write this in D's inline assembly perhaps, but there is one aspect that I am not sure how to do. The assembly code uses static allocation of registers, but because of the differences in how registers are used in Win64 versus Unix X64 - different registers are assigned depending on the architecture. dynasm makes this easy to do using macros; e.g. below. |.if X64WIN |.define CARG1, rcx // x64/WIN64 C call arguments. |.define CARG2, rdx |.define CARG3, r8 |.define CARG4, r9 |.else |.define CARG1, rdi // x64/POSIX C call arguments. |.define CARG2, rsi |.define CARG3, rdx |.define CARG4, rcx |.endif With above in place, the code can use the mnemonics to refer to the registers rather than the registers themselves. This allows the assembly code to be coded once for both architectures. How would one do this in D inline assembly? Thanks and Regards Dibyendu You could do it with a mixin, it would be rather ugly though. Not sure of another way off the top of my head.
Inline assembly question
Hi, I have recently started work on building a VM for Lua (actually a derivative of Lua) in X86-64 assembly. I am using the dynasm tool that is part of LuaJIT. I was wondering whether I could also write this in D's inline assembly perhaps, but there is one aspect that I am not sure how to do. The assembly code uses static allocation of registers, but because of the differences in how registers are used in Win64 versus Unix X64 - different registers are assigned depending on the architecture. dynasm makes this easy to do using macros; e.g. below. |.if X64WIN |.define CARG1, rcx // x64/WIN64 C call arguments. |.define CARG2, rdx |.define CARG3, r8 |.define CARG4, r9 |.else |.define CARG1, rdi // x64/POSIX C call arguments. |.define CARG2, rsi |.define CARG3, rdx |.define CARG4, rcx |.endif With above in place, the code can use the mnemonics to refer to the registers rather than the registers themselves. This allows the assembly code to be coded once for both architectures. How would one do this in D inline assembly? Thanks and Regards Dibyendu