Skip to content

Commit

Permalink
audio: Log context for audio bug
Browse files Browse the repository at this point in the history
Without this change audio_bug aborts when the bug condition is met,
which discards following useful logs. Call abort after such logs.

Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
  • Loading branch information
akihikodaki authored and philmd committed Mar 15, 2022
1 parent c9c8474 commit 8e30d39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
25 changes: 12 additions & 13 deletions audio/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ int audio_bug (const char *funcname, int cond)
AUD_log (NULL, "I am sorry\n");
}
AUD_log (NULL, "Context:\n");
abort();
}

return cond;
Expand All @@ -138,7 +137,7 @@ static inline int audio_bits_to_index (int bits)
default:
audio_bug ("bits_to_index", 1);
AUD_log (NULL, "invalid bits %d\n", bits);
return 0;
abort();
}
}

Expand All @@ -156,7 +155,7 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size)
AUD_log (NULL, "%s passed invalid arguments to audio_calloc\n",
funcname);
AUD_log (NULL, "nmemb=%d size=%zu (len=%zu)\n", nmemb, size, len);
return NULL;
abort();
}

return g_malloc0 (len);
Expand Down Expand Up @@ -543,7 +542,7 @@ static size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw)
size_t live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
if (audio_bug(__func__, live > hw->conv_buf->size)) {
dolog("live=%zu hw->conv_buf->size=%zu\n", live, hw->conv_buf->size);
return 0;
abort();
}
return live;
}
Expand Down Expand Up @@ -581,7 +580,7 @@ static size_t audio_pcm_sw_read(SWVoiceIn *sw, void *buf, size_t size)
}
if (audio_bug(__func__, live > hw->conv_buf->size)) {
dolog("live_in=%zu hw->conv_buf->size=%zu\n", live, hw->conv_buf->size);
return 0;
abort();
}

rpos = audio_ring_posb(hw->conv_buf->pos, live, hw->conv_buf->size);
Expand Down Expand Up @@ -656,7 +655,7 @@ static size_t audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)

if (audio_bug(__func__, live > hw->mix_buf->size)) {
dolog("live=%zu hw->mix_buf->size=%zu\n", live, hw->mix_buf->size);
return 0;
abort();
}
return live;
}
Expand Down Expand Up @@ -706,7 +705,7 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t size)
live = sw->total_hw_samples_mixed;
if (audio_bug(__func__, live > hwsamples)) {
dolog("live=%zu hw->mix_buf->size=%zu\n", live, hwsamples);
return 0;
abort();
}

if (live == hwsamples) {
Expand Down Expand Up @@ -998,7 +997,7 @@ static size_t audio_get_avail (SWVoiceIn *sw)
if (audio_bug(__func__, live > sw->hw->conv_buf->size)) {
dolog("live=%zu sw->hw->conv_buf->size=%zu\n", live,
sw->hw->conv_buf->size);
return 0;
abort();
}

ldebug (
Expand Down Expand Up @@ -1028,7 +1027,7 @@ static size_t audio_get_free(SWVoiceOut *sw)
if (audio_bug(__func__, live > sw->hw->mix_buf->size)) {
dolog("live=%zu sw->hw->mix_buf->size=%zu\n", live,
sw->hw->mix_buf->size);
return 0;
abort();
}

dead = sw->hw->mix_buf->size - live;
Expand Down Expand Up @@ -1170,7 +1169,7 @@ static void audio_run_out (AudioState *s)

if (audio_bug(__func__, live > hw->mix_buf->size)) {
dolog("live=%zu hw->mix_buf->size=%zu\n", live, hw->mix_buf->size);
continue;
abort();
}

if (hw->pending_disable && !nb_live) {
Expand Down Expand Up @@ -1203,7 +1202,7 @@ static void audio_run_out (AudioState *s)
if (audio_bug(__func__, hw->mix_buf->pos >= hw->mix_buf->size)) {
dolog("hw->mix_buf->pos=%zu hw->mix_buf->size=%zu played=%zu\n",
hw->mix_buf->pos, hw->mix_buf->size, played);
hw->mix_buf->pos = 0;
abort();
}

#ifdef DEBUG_OUT
Expand All @@ -1223,7 +1222,7 @@ static void audio_run_out (AudioState *s)
if (audio_bug(__func__, played > sw->total_hw_samples_mixed)) {
dolog("played=%zu sw->total_hw_samples_mixed=%zu\n",
played, sw->total_hw_samples_mixed);
played = sw->total_hw_samples_mixed;
abort();
}

sw->total_hw_samples_mixed -= played;
Expand Down Expand Up @@ -1346,7 +1345,7 @@ static void audio_run_capture (AudioState *s)
if (audio_bug(__func__, captured > sw->total_hw_samples_mixed)) {
dolog("captured=%zu sw->total_hw_samples_mixed=%zu\n",
captured, sw->total_hw_samples_mixed);
captured = sw->total_hw_samples_mixed;
abort();
}

sw->total_hw_samples_mixed -= captured;
Expand Down
27 changes: 12 additions & 15 deletions audio/audio_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
if (audio_bug(__func__, !voice_size && max_voices)) {
dolog ("drv=`%s' voice_size=0 max_voices=%d\n",
drv->name, max_voices);
glue (s->nb_hw_voices_, TYPE) = 0;
abort();
}

if (audio_bug(__func__, voice_size && !max_voices)) {
dolog ("drv=`%s' voice_size=%d max_voices=0\n",
drv->name, voice_size);
abort();
}
}

Expand All @@ -81,6 +82,7 @@ static void glue(audio_pcm_hw_alloc_resources_, TYPE)(HW *hw)
size_t samples = hw->samples;
if (audio_bug(__func__, samples == 0)) {
dolog("Attempted to allocate empty buffer\n");
abort();
}

HWBUF = g_malloc0(sizeof(STSampleBuffer) + sizeof(st_sample) * samples);
Expand Down Expand Up @@ -252,12 +254,12 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,

if (audio_bug(__func__, !drv)) {
dolog ("No host audio driver\n");
return NULL;
abort();
}

if (audio_bug(__func__, !drv->pcm_ops)) {
dolog ("Host audio driver without pcm_ops\n");
return NULL;
abort();
}

hw = audio_calloc(__func__, 1, glue(drv->voice_size_, TYPE));
Expand All @@ -275,12 +277,13 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
QLIST_INIT (&hw->cap_head);
#endif
if (glue (hw->pcm_ops->init_, TYPE) (hw, as, s->drv_opaque)) {
goto err0;
g_free(hw);
return NULL;
}

if (audio_bug(__func__, hw->samples <= 0)) {
dolog("hw->samples=%zd\n", hw->samples);
goto err1;
abort();
}

if (hw->info.is_float) {
Expand Down Expand Up @@ -309,12 +312,6 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
audio_attach_capture (hw);
#endif
return hw;

err1:
glue (hw->pcm_ops->fini_, TYPE) (hw);
err0:
g_free (hw);
return NULL;
}

AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
Expand Down Expand Up @@ -435,7 +432,7 @@ void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
if (sw) {
if (audio_bug(__func__, !card)) {
dolog ("card=%p\n", card);
return;
abort();
}

glue (audio_close_, TYPE) (sw);
Expand All @@ -457,7 +454,7 @@ SW *glue (AUD_open_, TYPE) (
if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
dolog ("card=%p name=%p callback_fn=%p as=%p\n",
card, name, callback_fn, as);
goto fail;
abort();
}

s = card->state;
Expand All @@ -468,12 +465,12 @@ SW *glue (AUD_open_, TYPE) (

if (audio_bug(__func__, audio_validate_settings(as))) {
audio_print_settings (as);
goto fail;
abort();
}

if (audio_bug(__func__, !s->drv)) {
dolog ("Can not open `%s' (no host audio driver)\n", name);
goto fail;
abort();
}

if (sw && audio_pcm_info_eq (&sw->info, as)) {
Expand Down

0 comments on commit 8e30d39

Please sign in to comment.