{"thread":{"id":"26487","subject":"[PATCH] Don't optimize code in debug build","startedAt":"2011-02-13T08:32:56Z","lastAt":"2011-02-13T19:28:24Z","messageCount":4,"participants":["Piotr Krukowiecki","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"160980","messageId":"AANLkTinw7DJ3hP7ACcScHTYy-Dvizq-OxefP6e0dEBbR@mail.gmail.com","threadId":"26487","inReplyTo":null,"subject":"[PATCH] Don't optimize code in debug build","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki.news@gmail.com","sentAt":"2011-02-13T08:32:56Z","receivedAt":"2011-02-13T08:32:56Z","isPatch":true,"sender":{"key":"piotr.krukowiecki.news@gmail.com","avatar":null},"body":"Code optimization makes debugging harder.\n\nSigned-off-by: Piotr Krukowiecki <piotr.krukowiecki.news@gmail.com>\n---\nMy first patch to this list, so please be gentle ;)\n\nPatch fixes most important problem. There are other improvement possible:\n- \"-g\" is not needed in normal build IMO, I'd move it to debug\n- I'd add -O0 -fno-inline to debug too, but maybe it's too gccish\n(OTOH there's -g already)\n\n Makefile |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex ade7923..32d3a69 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -262,7 +262,10 @@ endif\n\n # CFLAGS and LDFLAGS are for the users to override from the command line.\n\n-CFLAGS = -g -O2 -Wall\n+CFLAGS = -g -Wall\n+ifndef DEBUG\n+CFLAGS += -O2\n+endif\n LDFLAGS =\n ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)\n ALL_LDFLAGS = $(LDFLAGS)\n-- \n1.7.1\n\n-- \nPiotrek\n"},{"id":"160985","messageId":"201102131036.51311.j6t@kdbg.org","threadId":"26487","inReplyTo":"AANLkTinw7DJ3hP7ACcScHTYy-Dvizq-OxefP6e0dEBbR@mail.gmail.com","subject":"Re: [PATCH] Don't optimize code in debug build","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2011-02-13T09:36:50Z","receivedAt":"2011-02-13T09:36:50Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Sonntag, 13. Februar 2011, Piotr Krukowiecki wrote:\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -262,7 +262,10 @@ endif\n>\n>  # CFLAGS and LDFLAGS are for the users to override from the command line.\n>\n> -CFLAGS = -g -O2 -Wall\n> +CFLAGS = -g -Wall\n> +ifndef DEBUG\n> +CFLAGS += -O2\n> +endif\n>  LDFLAGS =\n>  ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)\n>  ALL_LDFLAGS = $(LDFLAGS)\n\nInstead of this, you can just write\n\n CFLAGS = -g -Wall\n\nin your config.mak. Is anything wrong with that?\n\n-- Hannes\n"},{"id":"161007","messageId":"AANLkTinECgZwFZ0157O-qvYUW1GpJgbsHDekR1WM6gPm@mail.gmail.com","threadId":"26487","inReplyTo":"AANLkTim6OHU8N7t5RQnt6S7x7ez48RSwp=b82McAC4Oq@mail.gmail.com","subject":"Re: [PATCH] Don't optimize code in debug build","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki.news@gmail.com","sentAt":"2011-02-13T16:26:51Z","receivedAt":"2011-02-13T16:26:51Z","isPatch":true,"sender":{"key":"piotr.krukowiecki.news@gmail.com","avatar":null},"body":"(forgot about the list when replying)\n\n> On Sun, Feb 13, 2011 at 10:36 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n>> On Sonntag, 13. Februar 2011, Piotr Krukowiecki wrote:\n>>> --- a/Makefile\n>>> +++ b/Makefile\n>>> @@ -262,7 +262,10 @@ endif\n>>>\n>>>  # CFLAGS and LDFLAGS are for the users to override from the command line.\n>>>\n>>> -CFLAGS = -g -O2 -Wall\n>>> +CFLAGS = -g -Wall\n>>> +ifndef DEBUG\n>>> +CFLAGS += -O2\n>>> +endif\n>>>  LDFLAGS =\n>>>  ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)\n>>>  ALL_LDFLAGS = $(LDFLAGS)\n>>\n>> Instead of this, you can just write\n>>\n>>  CFLAGS = -g -Wall\n>>\n>> in your config.mak. Is anything wrong with that?\n\nSeveral things: I need to know I should remove -O2, I need to keep in\nsync with other default options, current default is less useful, it\nrequires me to do extra steps.\nDEBUG is kind of standard - Makefile already uses it in Windows\nspecific part. I suppose we want to keep consistent.\n\n-- \nPiotrek\n"},{"id":"161012","messageId":"7vbp2fybs7.fsf@alter.siamese.dyndns.org","threadId":"26487","inReplyTo":"201102131036.51311.j6t@kdbg.org","subject":"Re: [PATCH] Don't optimize code in debug build","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-13T19:28:24Z","receivedAt":"2011-02-13T19:28:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n>> @@ -262,7 +262,10 @@ endif\n>>\n>>  # CFLAGS and LDFLAGS are for the users to override from the command line.\n>>\n>> -CFLAGS = -g -O2 -Wall\n>> +CFLAGS = -g -Wall\n>> +ifndef DEBUG\n>> +CFLAGS += -O2\n>> +endif\n>>  LDFLAGS =\n>>  ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)\n>>  ALL_LDFLAGS = $(LDFLAGS)\n>\n> Instead of this, you can just write\n>\n>  CFLAGS = -g -Wall\n>\n> in your config.mak. Is anything wrong with that?\n\nYou then need to feed -O2 from the command line when you are not doing a\ndebugging build.  On the other hand, with the current Makefile, you need\nto feed \"-g -O0\" from the command line when you are doing a debugging\nbuild if you and your debugger get confused when seeing an optimized\nbinary.  So neither is a very good solution.\n\nBut having to feed DEBUG=Yes when running a debug build is not a good\nsolution either.  A single toggle is simply too coarse-grained; the next\ntemptation after applying this patch would be to add\n\n\tifdef DEBUG\n        CFLAGS += -DDEBUG\n        endif\n\nand from there everything goes downhill.  That is the last thing we would\nwant to see happen.\n\nSo I would say the current Makefile is just fine as is.\n"}]}