Skip to content

Commit a0e0951

Browse files
author
rsora
committed
add debug symbols option in CLI and gRPC insterface
1 parent 18f2eb3 commit a0e0951

File tree

8 files changed

+75
-45
lines changed

8 files changed

+75
-45
lines changed

cli/compile/compile.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
verify bool // Upload, verify uploaded binary after the upload.
4949
exportFile string // The compiled binary is written to this file
5050
libraries []string // List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths.
51+
optimizeForDebug bool // Optimize compile output for debug, not for release
5152
)
5253

5354
// NewCommand created a new `compile` command
@@ -80,6 +81,7 @@ func NewCommand() *cobra.Command {
8081
command.Flags().StringVar(&vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.")
8182
command.Flags().StringSliceVar(&libraries, "libraries", []string{},
8283
"List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths.")
84+
command.Flags().BoolVar(&optimizeForDebug, "optimize-for-debug", false, "Optional, optimize compile output for debug, not for release.")
8385

8486
return command
8587
}
@@ -99,20 +101,21 @@ func run(cmd *cobra.Command, args []string) {
99101
sketchPath := initSketchPath(path)
100102

101103
_, err = compile.Compile(context.Background(), &rpc.CompileReq{
102-
Instance: inst,
103-
Fqbn: fqbn,
104-
SketchPath: sketchPath.String(),
105-
ShowProperties: showProperties,
106-
Preprocess: preprocess,
107-
BuildCachePath: buildCachePath,
108-
BuildPath: buildPath,
109-
BuildProperties: buildProperties,
110-
Warnings: warnings,
111-
Verbose: verbose,
112-
Quiet: quiet,
113-
VidPid: vidPid,
114-
ExportFile: exportFile,
115-
Libraries: libraries,
104+
Instance: inst,
105+
Fqbn: fqbn,
106+
SketchPath: sketchPath.String(),
107+
ShowProperties: showProperties,
108+
Preprocess: preprocess,
109+
BuildCachePath: buildCachePath,
110+
BuildPath: buildPath,
111+
BuildProperties: buildProperties,
112+
Warnings: warnings,
113+
Verbose: verbose,
114+
Quiet: quiet,
115+
VidPid: vidPid,
116+
ExportFile: exportFile,
117+
Libraries: libraries,
118+
OptimizeForDebug: optimizeForDebug,
116119
}, os.Stdout, os.Stderr, viper.GetString("logging.level") == "debug")
117120

118121
if err != nil {

commands/compile/compile.go

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
103103

104104
builderCtx.Verbose = req.GetVerbose()
105105

106+
// Optimize for debug
107+
builderCtx.OptimizeForDebug = req.GetOptimizeForDebug()
108+
106109
builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino-core-cache")
107110

108111
builderCtx.Jobs = int(req.GetJobs())

legacy/builder/create_build_options_map.go

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package builder
1717

1818
import (
1919
"encoding/json"
20-
2120
"github.com/arduino/arduino-cli/legacy/builder/i18n"
2221
"github.com/arduino/arduino-cli/legacy/builder/types"
2322
)
@@ -30,7 +29,6 @@ func (s *CreateBuildOptionsMap) Run(ctx *types.Context) error {
3029
if err != nil {
3130
return i18n.WrapError(err)
3231
}
33-
3432
ctx.BuildOptionsJson = string(bytes)
3533

3634
return nil

legacy/builder/setup_build_properties.go

+11
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
6969
buildProperties.Set("ide_version", ctx.ArduinoAPIVersion)
7070
buildProperties.Set("runtime.os", utils.PrettyOSName())
7171

72+
if ctx.OptimizeForDebug {
73+
if buildProperties.ContainsKey("compiler.optimization_flags.debug") {
74+
buildProperties.Set("compiler.optimization_flags", buildProperties.Get("compiler.optimization_flags.debug"))
75+
}
76+
} else {
77+
if buildProperties.ContainsKey("compiler.optimization_flags.release") {
78+
buildProperties.Set("compiler.optimization_flags", buildProperties.Get("compiler.optimization_flags.release"))
79+
}
80+
}
81+
ctx.OptimizationFlags = buildProperties.Get("compiler.optimization_flags")
82+
7283
variant := buildProperties.Get("build.variant")
7384
if variant == "" {
7485
buildProperties.Set("build.variant.path", "")

legacy/builder/types/context.go

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ type Context struct {
9494
Verbose bool
9595
DebugPreprocessor bool
9696

97+
// Compile optimization settings
98+
OptimizeForDebug bool
99+
OptimizationFlags string
100+
97101
// Dry run, only create progress map
98102
Progress ProgressStruct
99103

@@ -140,6 +144,7 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
140144
opts.Set("runtime.ide.version", ctx.ArduinoAPIVersion)
141145
opts.Set("customBuildProperties", strings.Join(ctx.CustomBuildProperties, ","))
142146
opts.Set("additionalFiles", strings.Join(additionalFilesRelative, ","))
147+
opts.Set("compiler.optimization_flags", ctx.OptimizationFlags)
143148
return opts
144149
}
145150

@@ -156,6 +161,7 @@ func (ctx *Context) InjectBuildOptions(opts *properties.Map) {
156161
ctx.FQBN = fqbn
157162
ctx.ArduinoAPIVersion = opts.Get("runtime.ide.version")
158163
ctx.CustomBuildProperties = strings.Split(opts.Get("customBuildProperties"), ",")
164+
ctx.OptimizationFlags = opts.Get("compiler.optimization_flags")
159165
}
160166

161167
func (ctx *Context) GetLogger() i18n.Logger {

rpc/commands/compile.pb.go

+36-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/commands/compile.proto

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ message CompileReq {
3737
string exportFile = 13; // The compiled binary is written to this file
3838
int32 jobs = 14; // The max number of concurrent compiler instances to run (as make -jx)
3939
repeated string libraries = 15; // List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths.
40+
bool optimizeForDebug = 16; // Optimize compile output for debug, not for release
4041
}
4142

4243
message CompileResp {

rpc/debug/debug.pb.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)